将 Excel 工作表另存为 HTML

编程入门 行业动态 更新时间:2024-10-08 13:30:42
本文介绍了将 Excel 工作表另存为 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试将工作簿 (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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 14:12:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:另存为   工作   Excel   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!