将 Excel 工作表另存为 HTML [英] Save Excel sheets as HTML

查看:45
本文介绍了将 Excel 工作表另存为 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将工作簿 (foo,bar,baz) 中的每个工作表保存为单独的 HTML 文档(foo.html,bar.html,baz.html):

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

结果:

  • Output 中每个工作表(名为 _files)的文件夹,其中包含每个工作表的 HTML 文档(名为 sheet<n>.html),以及一些额外的文件(filelist.xmlstylesheet.csstabstrip.html)

  • 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)

Output 中每个工作表(名为 .html`)的文件,引用相应的文件夹

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

我该如何纠正?

推荐答案

这个脚本:

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.HTML),以及其他文件(filelist.xml)>,stylesheet.css,tabstrip.html)
  • 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)

这篇关于将 Excel 工作表另存为 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆