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



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

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

我想知道是否有人能帮我完成"待办事项"这几行。在执行时,这个脚本会给我一个对话框,上面有我放在上面的文件的路径。但是excel应用程序抛出一个错误对话框,上面写着"内存不足"。我只用了2个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

非常感谢

我不了解所有内容-->将文件名插入该列的每一行|TO DO每列中的文本插入到每个文件的名称。

这是脚本,更新:

    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

编辑:我忘记了错误:

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

像这样使用myset x to my addFilePath(eachFile)

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

最新更新