使用Applescript从Excel保存干净的CSV文件

时间:2011-04-16 18:58:11

标签: excel applescript

我有一个流程需要从Web下载Excel电子表格,使用Excel Mac 2008打开它,将其保存为csv文件,然后使用php解析它。手动过程工作正常,并保存一个干净的CSV文件。我正在尝试使用Applescript自动化这个部分,它有点工作,但是,生成的CSV文件包含一堆奇怪的字符。

以下是我正在处理的Applescript:

tell application id "com.microsoft.Excel" to open "~/Documents/input.xls"
tell application id "com.microsoft.Excel" to tell active sheet to save in ("output.csv") as "CSV file format"

我尝试了各种CSV选项(Mac,Windows,MSDos),但它们的结果并没有大不相同。

1 个答案:

答案 0 :(得分:3)

试试这个......

set theDoc to (path to desktop as text) & "test.xlsx"
set outPath to (path to desktop as text) & "test.csv"

tell application "Microsoft Excel"
    open file theDoc
    tell workbook 1
        tell sheet 1
            save in outPath as CSV file format
        end tell
        close without saving
    end tell
end tell