代码之家  ›  专栏  ›  技术社区  ›  banditKing

以下是一些在Snow Leopard上与Microsoft Excel交互的Applescript代码-如何添加缺失的函数

  •  0
  • banditKing  · 技术社区  · 12 年前

    我有大约400个excel文件。我想在现有文件的第一列之前插入一列,然后将文件名插入该列的每一行。

    我知道一点Applescript,基于此,我编写了这个脚本,这样我就可以将一些文件放到脚本中,它会在每个文件上执行脚本。

    我想知道是否有人能帮我完成“待办事项”这几行。在执行时,这个脚本会给我一个对话框,上面有我放在上面的文件的路径。但是excel应用程序抛出一个错误对话框,上面写着“内存不足”。我只尝试了两个excel文件,所以导致错误的不是文件的数量。

    有人能帮我完成TODO行吗?并告诉我为什么会出错。谢谢

    property numFiles : 0
    
    on open excelFiles
    
    
    set fileNames to ""
    
    tell application "Finder"
        repeat with eachFile in excelFiles
    
            --open document file eachFile
    
            --tell application "Microsoft Excel"
    
            --increment count
    
    
    
            --save name of each file
    
            set fileNames to fileNames & return & (POSIX path of eachFile)
    
            --TO DO insert a column
    
            --TO DO insert text in each column to the name of eachFile
    
            --end tell
        end repeat
        display dialog fileNames
        --display dialog "Ouch that hurt " & return & "You dropped " & (count excelFiles) & "files on me"
    end tell
    end open
    
    on addFilePath(eachFile)
    set fileNames to fileNames & (POSIX path of eachFile)
    end addFilePath
    

    非常感谢

    1 回复  |  直到 12 年前
        1
  •  1
  •   jackjr300    12 年前

    我不是什么都懂-->将文件名插入该列的每一行| 去做 在中插入文本 每列 到每个文件的名称。

    这是剧本, 更新时间:

        on open excelFiles
        set numFiles to count excelFiles
        repeat with eachFile in excelFiles -- open each file in Excel
            tell application "Microsoft Excel"
                set tBook to open workbook workbook file name (eachFile as string)
                set tName to name of tBook
                insert into range column 1 of active sheet -- insert column
    
                set lastCell to last cell of used range of active sheet -- get last cell from the used range
                set value of range ("A1:A" & first row index of lastCell) of active sheet to tName --set first column's values to the file name
    
                close tBook saving yes
            end tell
        end repeat
        display dialog numFiles
    end open
    

    编辑:我忘记了错误:

    内存不足 :这个奇怪的错误似乎是:调用处理程序时没有使用 my tell me to )在 tell block application

    使用 我的 像这样: set x to my addFilePath(eachFile)

    此外 tell application "Microsoft Excel" 中的块 application Finder 不建议使用块,这可能会导致意外错误。