我有.xls文件的文件夹,其中一些是正版excel文件,一些是excel xml文件(但仍然使用.xls扩展名)。为了在单独的程序中处理文件,我试图将它们全部转换为一致的格式(Excel 98-2004),并希望使用applescript来保留原始文件名和目录结构。< / p>
截至目前,我有一个工作循环和文件列表,并且正在完成除保存功能之外的所有内容:
set file_Name to "/Users/me/path/to/data.xls"
tell application "Microsoft Excel"
activate
open file_Name
save workbook as workbook (active workbook) filename file_Name file format (Excel98to2004 file format) with overwrite
close workbooks
quit
end tell
当我运行此代码时,我收到以下回复:
tell application "Microsoft Excel"
activate
open "/Users/drewmcdonald/Desktop/Madhupur_10February2014.xls"
get active workbook
--> active workbook
save workbook as workbook (active workbook) filename "/Users/drewmcdonald/Desktop/test.xlsx"
--> missing value
close every workbook
quit
end tell
电子表格是成功打开和关闭的,但文件格式没有变化,我不知道该怎么做&#34;缺失值&#34;错误。知道如何让这个工作吗?谢谢!
编辑:注意到回复文本中缺少文件格式参数,因此我猜测问题就在那里。
答案 0 :(得分:2)
知道了。
在尝试保存之前,我需要将set
工作簿名称变量设置为get full name of active workbook
。这是因为Excel打开工作表时分配的工作簿名称有些不一致。最终代码如下所示:
set file_Name to "/Users/me/path/to/data.xls"
tell application "Microsoft Excel"
activate
open file_Name
set wkbk_name to get full name of active workbook
save workbook as workbook wkbk_name filename file_Name file format Excel98to2004 file format with overwrite
close workbooks
quit
end tell