Applescript + Microsoft Word - “另存为”的文件类型?

时间:2012-07-07 18:00:42

标签: macos ms-word applescript

我正在尝试编写一个脚本,以单文件网页(.mht)格式保存Word文档。我在编写实际的“保存”命令的部分,我被困在那里。这就是我想要做的事情:

# the_file is a variable which has been set here
tell application "Microsoft Word"
    activate
    open the_file
    save the_file as [type]
end tell

开放部分工作正常。但是我不知道要为保存类型添加什么。也许更重要的是,我不知道在哪里可以找到可用类型的列表。有人可以帮忙吗?

编辑:一位评论者提出词典;我在那里发现了以下内容,但不知道如何解释它[我是AS noob]。

[file format format document97/‌format document97/‌format template97/‌format template97/‌format text/‌format text line breaks/‌format dostext/‌format dostext line breaks/‌format rtf/‌format Unicode text/‌format Unicode text/‌format HTML/‌format web archive/‌format stationery/‌format xml/‌format document/‌format documentME/‌format template/‌format templateME/‌format PDF/‌format flat document/‌format flat documentME/‌format flat template/‌format flat templateME/‌format custom dictionary/‌format exclude dictionary/‌format documentAuto/‌format templateAuto] : The format in which the document is saved.

2 个答案:

答案 0 :(得分:2)

试试format web archive。在列出的所有格式中,最有可能的那种格式。

答案 1 :(得分:0)

1-您必须在使用save命令时指定文档,而不是文件路径。 为了更好地控制,使用带有属性open的{​​{1}}命令,它将返回文档对象。

使用时:file name,它不返回任何内容,在这种情况下,您必须使用open the_file,但它不可靠,例如,如果之后打开了其他文档。

2- Word在 Applescript 中使用front document命令时不会更改扩展名,脚本必须替换扩展名。 另外,我建议命令save使用更多选项而不是save as

已更新答案:格式化HTML ,而不是网络存档

save

如果您不想set the_file to (choose file) tell application "Microsoft Word" set thisDoc to open file name (the_file as string) set tName to my removeExtension(name of thisDoc) -- save in the same directory save as thisDoc file format format HTML file name (tName & ".htm") with HTML display only output close thisDoc saving no end tell on removeExtension(t) if t does not contain "." then return t set tid to text item delimiters set text item delimiters to "." set t to (text items 1 thru -2 of t) as string set text item delimiters to tid return t end removeExtension ,请使用HTML display only output