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

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

我从另一个帖子的答案中复制了此内容。我正在尝试将约 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

它只会打开一个对话框,什么也不做。尽管它本来是一个 droplet,但当我将文件拖到它上面时什么也没发生。

答案1

我们再见面。 :)

将脚本剪切并粘贴到 AppleScript 编辑器的新窗口中。保存时,在窗口底部的“文件格式”处选择“应用程序”。这将启用拖放功能。

相关内容