使用Applescript生成并写入excel文件

时间:2017-10-03 18:53:13

标签: excel applescript applescript-excel

AppleScript新手,但我正在开发一个脚本,该脚本获取图像文件夹,获取名称,颜色配置文件,宽度,高度,并计算每个图像的宽高比(WxH)并将所有信息导出到excel文件。只需写入.csv就可以成功完成此操作,但现在我实际上想写入.xls,所以我也可以对宽高比列进行一些条件格式化。下面是导致问题的代码块。当我去编译时,我得到以下错误:

  

AppleScript编译错误

     

无法设置«class ccel»«A“& amp;«class DPVu» num到imgName。不允许访问。

第一个“单元格设置值”语句出现此错误。如果我一次一个地评论这些行并编译,它会为每个行抛出相同的错误。

我已经尝试使用谷歌搜索我认为谷歌的一切,但没有发现任何有用的东西......

代码:

--counter variable for excel row placement. (row 1 is a header row)
set num to 2

repeat with img in imgFolder
    --write specs to excel file
    tell application "Microsoft Excel"
        set value of Cell "A"&num to imgName
        set value of Cell "B"&num to imgColorProfile
        set value of Cell "C"&num to imgWidth
        set value of Cell "D"&num to imgHeight
        set value of Cell "E"&num to imgRatio
    end tell

--incremental counter for next excel row
    set num to num + 1
end repeat

1 个答案:

答案 0 :(得分:0)

我会写更简单的

set num to 2

repeat with img in imgFolder
    --write specs to excel file
    tell application "Microsoft Excel"
        tell row num
            set value of cell 1 to imgName
            set value of cell 2 to imgColorProfile
            set value of cell 3 to imgWidth
            set value of cell 4 to imgHeight
            set value of cell 5 to imgRatio
        end tell
    end tell

--incremental counter for next excel row
    set num to num + 1
end repeat
相关问题