问题
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
Outputfor each sheet (named<sheet name>_files) that contains an HTML document for each sheet (namedsheet<n>.html), plus a few additional files (filelist.xml,stylesheet.css,tabstrip.html)a file in
Outputfor 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