保存Excel工作表作为HTML(Save Excel sheets as HTML)

2019-10-21 12:58发布

我试图每个片材(保存在工作簿foobarbaz )作为一个单独的HTML文档( foo.htmlbar.htmlbaz.html ):

set theDirectory to (path to desktop as text) & "Output:"

set theSource to choose file with prompt "Choose file:" default location "/Users/<user>/Desktop/" of type {"XLS", "XLSX"}

tell application "Microsoft Excel"

    activate

    set theWorkbook to open theSource

    set theSheets to every sheet of active workbook

    repeat with theSheet in theSheets

        set theDestination to theDirectory & (the name of theSheet) & ".html"
        log theDestination

        tell theSheet
            save as sheet filename theDestination file format HTML file format
        end tell

    end repeat

    quit saving no

end tell

这个结果:

  • 在一个文件夹中Output对于每个片材(命名为<sheet name>_files包含一个HTML文档的每个片材(命名) sheet<n>.html ),再加上一些附加的文件( filelist.xmlstylesheet.csstabstrip.html

  • 在文件Output对于每个片(名为.html`)引用该对应的文件夹

如何纠正呢?

Answer 1:

这个脚本:

set theSource to choose file with prompt "Choose file:" default location (path to desktop) of type {"XLS", "XLSX"}
set theDestination to (choose folder with prompt "Choose destination folder:" default location path to desktop)
set thePath to (theDestination as text) & "data.HTML"

tell application "Microsoft Excel"
    activate
    open theSource
    tell active workbook
        save as active sheet filename thePath file format HTML file format
    end tell
    quit saving no
end tell

会产生:

  • 一档名为data.HTML
  • 一个文件夹名为data_files ,含有一个文件用于每个片材( sheet<NNN>.HTML ),加上附加的文件( filelist.xmlstylesheet.csstabstrip.html


文章来源: Save Excel sheets as HTML