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

发布于 2024-11-01 23:20:04 字数 459 浏览 1 评论 0原文

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

I have a process that requires downloading an Excel Spreadsheet from the Web, opening it using Excel Mac 2008, saving it as a csv file, and then parsing it using php. The manual process works fine and saves a clean CSV file. I am trying to automate this part using Applescript, and it sort of works, however, the CSV file generated contains a bunch of weird characters.

Here is the Applescript I am working on:

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"

I have tried various CSV options (Mac, Windows, MSDos) and they do not produce substantially different results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2024-11-08 23:20:04

试试这个...

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

Try this...

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文