【问题标题】:Save Clean CSV file from Excel using Applescript使用 Applescript 从 Excel 中保存干净的 CSV 文件
【发布时间】:2011-04-17 19:17:14
【问题描述】:

我有一个过程,需要从 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),但它们并没有产生明显不同的结果。

【问题讨论】:

  • 有什么方法可以让 Excel 退出该过程,只使用生成 Excel 文件的任何内容生成 CSV?在我看来,你可以节省很多潜在的问题,因为一旦 Excel 更新,你可能会重写它。
  • 菲利普:很遗憾,没有。 Excel 文件是从一个不太友好的网站输出的,输出选项有 html、pdf 和 Excel。在这三者中,Excel 是最容易解析的。

标签: excel applescript


【解决方案1】:

试试这个...

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

【讨论】:

  • regulus6633 谢谢 - 除了告诉块之外,主要区别似乎是您的另存为命令中没有围绕 CSV 文件格式的引号。我试过你的,效果很好,然后我尝试删除引号,效果也很好。
猜你喜欢
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多