2010-01-07 104 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

相關問題