Save Excel sheets as HTML

亡梦爱人 提交于 2019-12-11 05:20:04

问题


I'm attempting to save each sheet in a workbook (foo,bar,baz) as a separate HTML document (foo.html,bar.html,baz.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

This results:

  • a folder in Output for each sheet (named <sheet name>_files) that contains an HTML document for each sheet (named sheet<n>.html), plus a few additional files (filelist.xml,stylesheet.css,tabstrip.html)

  • a file in Output for each sheet (named .html`) that references the corresponding folder

How do I correct this?


回答1:


This script:

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

Will generate:

  • a file named data.HTML
  • a folder named data_files, containing a document for each sheet (sheet<NNN>.HTML), plus additional files (filelist.xml,stylesheet.css,tabstrip.html)


来源:https://stackoverflow.com/questions/27803898/save-excel-sheets-as-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!