2010-01-07 108 views
3

我想将通过OpenOffice.org UNO创建的TextDocument保存到磁盘上的文件中。做这个的最好方式是什么?如何以编程方式将文档保存在OpenOffice.org中?

编辑:这是我最终使用的C#代码。 documentXTextDocument

protected void Save (string path) 
{ 
    string url = "file://" + path; 
    PropertyValue [] propertyValues = { 
     new PropertyValue { 
      Name = "FilterName", 
      Value = new Any ("writer8") 
     } 
    }; 
    ((XStorable) document).storeAsURL (url, propertyValues); 
} 
+0

在哪种语言? – 2010-01-07 19:05:23

+0

我正在使用C#,但如果您使用其他语言回答,则可以将其转换为C#。 – 2010-01-07 19:06:35

+3

小心你想要什么 - ++++ [> +++++ <-]> [<+++++> - ] + <+[> [> +> + <<-]++>> [<<+>> - ] >>> [ - ] ++> [ - ] + >>> + [[ - ] ++++++> >>] <<< [[<++++++++<++>> - ] + <.<[> ---- <-]<]<<[> >>>> [>>> [ - ] +++ ++++++ <[> - < - ] +++++++++ > [ - [<-> - ] + [<<<]]<[> + <-]>] << - ] << - ] – 2010-01-07 19:14:40

回答

2

使用XStorable.storeToURL()(或storeAsURL)。

编辑:你需要通过一个FilterName与输出格式。例子(在Python中因为这很简单):

properties = (PropertyValue('FilterName', 0, 'writer8', 0),) 
document.storeToURL('file:///path/to/document.odt', properties) 
+0

即使文档说第二个参数是可选的,storeToURL()和storeAsURL()也需要2个参数。我尝试传递'null'作为第二,但我得到一个IOException。我现在正在浏览文档,但是你知道如何解决这个问题吗?如果我能弄清楚如何设置文档的默认URL,我可以使用'store()'方法并避免整个问题。 – 2010-01-07 19:28:58

+0

谢谢,这个作品完美。我将这段代码的C#版本添加到了我的问题中。 – 2010-01-07 20:01:20

相关问题