gpt4 book ai didi

excel - 尝试使用 AppleScript 将 .xls 和 .xlsx 转换为 .txt(制表符分隔),需要修复

转载 作者:行者123 更新时间:2023-12-04 20:00:20 25 4
gpt4 key购买 nike

我从另一个线程得到的答案复制了这个。我正在尝试将 ~300 个 .xls 和 .xlsx 文件转换为制表符分隔。它们都在同一个文件夹中。如果有人知道更好的方法,请告诉我。

property type_list : {"XLS6", "XLS7", "XLS8", "XLSX"}
property extension_list : {"xls", "xlsx"}


on open these_workbooks
repeat with k from 1 to the count of these_workbooks
set this_item to item k of these_workbooks
set the item_info to info for this_item

--this if statement tests to make sure the items you're converting are Excel spreadsheets and not folders or aliases
if (folder of the item_info is false) and (alias of the item_info is false) and ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then

tell application "Finder" to open this_item

tell application "Microsoft Excel"
--this just tacks on ".txt" to your file name
set workbookName to (name of active workbook & ".txt")
--save the current open workbook as a tab-delimited text file
tell active workbook to save workbook as filename workbookName file format text Mac file format
close active workbook saving no
end tell
end if
end repeat
end open

on run
display dialog "Drop Excel files onto this icon."
end run

所有这一切都是打开一个对话框,什么都不做。即使它是一个液滴,当我将文件拖到它时也没有任何 react 。

最佳答案

在 Applescript 中,run处理程序在脚本或应用程序正常运行时运行。同时,open VarName处理程序在某些文件或文件为 dropped onto the icon 时运行应用程序和文件设置为变量 VarName .您发布的脚本巧妙地将 display dialogon run handler 试图帮助你理解这种用法​​。相反,将脚本保存为应用程序,然后将文件拖放到它上面。

编辑:

在终于拥有 Excel 2011 的 Mountain Lion 机器上进行了快速测试后(我没有意识到我有多么复杂):

property type_list : {"XLS6", "XLS7", "XLS8", "XLSX"}
property extension_list : {"xls", "xlsx"}


on open these_workbooks
repeat with k from 1 to the count of these_workbooks
set this_item to item k of these_workbooks
set the item_info to info for this_item

--this if statement tests to make sure the items you're converting are Excel spreadsheets and not folders or aliases
if (folder of the item_info is false) and (alias of the item_info is false) and ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then

tell application "Finder" to open this_item

tell application "Microsoft Excel"
--this just tacks on ".txt" to your file name
set workbookName to (path to desktop as string) & "After:" & (name of active workbook & ".txt")
display dialog workbookName
--save the current open workbook as a tab-delimited text file
tell active workbook to save workbook as filename workbookName file format text Mac file format
close active workbook saving no
end tell
end if
end repeat
end open

on run
display dialog "Drop Excel files onto this icon."
end run

关于excel - 尝试使用 AppleScript 将 .xls 和 .xlsx 转换为 .txt(制表符分隔),需要修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18259576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com