我正在尝试构建一个reStructuredText到MS Word文档的工具链,这样我就可以仅保存版本控制中的rst源文件。
到目前为止,我已经使用rst2odt.py将reStructuredText转换为OpenOffice.org Writer格式。
接下来,我想使用最新的OpenOffice.org(目前是3.1),它可以很好地生成Word 97/2000/XP文档,所以我编写了宏:
但是当我执行它时:
我遇到了一个错误:“BASIC运行时错误。找不到属性或方法。”出现在以下代码行:
当我注释掉那一行时,上面的调用完成而没有错误,但是什么也没做。 我猜我需要以某种方式将
到目前为止,我已经使用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)"
我遇到了一个错误:“BASIC运行时错误。找不到属性或方法。”出现在以下代码行:
document = ThisComponent.CurrentController.Frame
当我注释掉那一行时,上面的调用完成而没有错误,但是什么也没做。 我猜我需要以某种方式将
document
的值设置为一个新创建的实例,但我不知道如何做到这一点。
或者我完全走了弯路?
附言:我会考虑JODConverter作为备选方案,因为我试图尽量减少我的依赖。