【问题标题】:Using Applescript to generate and write to an excel file使用 Applescript 生成并写入 Excel 文件
【发布时间】:2020-07-02 03:01:21
【问题描述】:

AppleScript 新手,但我正在编写一个脚本,该脚本获取图像文件夹,获取名称、颜色配置文件、宽度、高度,并计算每个图像的纵横比 (WxH),并将所有这些信息导出到excel文件。简单地写入 .csv 时,我能够成功地做到这一点,但现在我实际上想写入 .xls,因此我还可以对纵横比列进行一些条件格式化。下面是导致麻烦的代码块。当我去编译时,我得到以下错误:

AppleScript 编译错误

无法将 «class ccel» "A" & num 的 «class DPVu» 设置为 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

【问题讨论】:

  • 你能展示剩下的代码吗?我的预感是这个位是如何放置在其中的。

标签: excel macos applescript


【解决方案1】:

我会写得更简单

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2013-09-26
    • 2018-05-20
    相关资源
    最近更新 更多