我正在尝试构建一个 reStructuredText到 MS Word 文档工具链,所以我将只能保存 rst版本控制中的源代码。
到目前为止我--
有rst2odt.py将 reStructuredText 转换为 OpenOffice.org Writer 格式。
接下来,我想使用最新的 OpenOffice.org(目前为 3.1),它在生成 Word 97/2000/XP 文档方面做得相当不错,所以我编写了宏:
sub ConvertToWord(file as string)
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim odf(1) as new com.sun.star.beans.PropertyValue
odf(0).Name = "URL"
odf(0).Value = "file://" + file + ".odt"
odf(1).Name = "FilterName"
odf(1).Value = "MS Word 97"
dispatcher.executeDispatch(document, ".uno:Open", "", 0, odf())
rem ----------------------------------------------------------------------
dim doc(1) as new com.sun.star.beans.PropertyValue
doc(0).Name = "URL"
doc(0).Value = "file://" + file + ".doc"
doc(1).Name = "FilterName"
doc(1).Value = "MS Word 97"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, doc())
end sub
但是当我执行它时:
soffice "macro:///Standard.Module1.ConvertToWord(/path/to/odt_file_wo_ext)"
我收到:“基本运行时错误。未找到属性或方法。”消息上线:
document = ThisComponent.CurrentController.Frame
当我评论该行时,上述调用完成且没有错误,但什么也不做。
我想我需要以某种方式将 document
的值设置为新创建的实例,但我不知道该怎么做。
或者我是在以一种完全落后的方式来处理它吗?
附言我会考虑JODConverter作为后备,因为我尽量减少我的依赖。
最佳答案
我建议使用 JODConverter(您的后备),因为您可以得到想要的东西,并且当/如果 OpenOffice/LibreOffice 对其 DOC 过滤器进行改进时,您不必每次都安装/升级/测试您的宏。这也得到了很好的证明。
关于automation - 使用 OpenOffice.org 基本宏以编程方式将 *.odt 文件转换为 MS Word *.doc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1340562/