Automation 使用OpenOffice.org基本宏以编程方式将*.odt文件转换为MS Word*.doc文件

Automation 使用OpenOffice.org基本宏以编程方式将*.odt文件转换为MS Word*.doc文件,automation,ms-word,openoffice.org,openoffice-basic,Automation,Ms Word,Openoffice.org,Openoffice Basic,我正在尝试构建一个到MS Word文档的工具链,因此我将能够在版本控制中只保存源代码 到目前为止我-- 必须将StructuredText转换为OpenOffice.org Writer格式 接下来,我想使用最新的OpenOffice.org(目前为3.1),它可以很好地生成Word 97/2000/XP文档,因此我编写了宏: sub ConvertToWord(file as string) rem ---------------------------------------------

我正在尝试构建一个到MS Word文档的工具链,因此我将能够在版本控制中只保存源代码

到目前为止我--

必须将StructuredText转换为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
的值设置为一个新创建的实例,但我不知道怎么做

还是我在以一种完全落后的方式去做


< P.S.S.我将考虑作为一个回退,因为我试图最小化我的依赖。

< P>我建议使用JoD转换器(你的回退),因为你得到了你想要的,当/OpenOffice/LyBrice对他们的DOC过滤器进行改进时,你不必每次都安装/升级/测试你的宏。事实也证明了这一点