2011-01-29 73 views
0

我正在用C#創建一個OO Writer文檔。使用C#我已經不知道我是否進入或離開,我已經嘗試了這麼多變化....OpenOffice Writer使用C的問題#

,已經有人成功地得到了以下工作 -

任何幫助,將不勝感激?我只有一個簡單的2列表格,並且希望將列寬設置爲不同的值(此階段的實際值不重要 - 只是不相同的寬度)。

此代碼是根據各種網絡資源調整的,這些網頁資源是作爲列寬度的示例。我不能得到它的工作....

//For OpenOffice.... 
using unoidl.com.sun.star.lang; 
using unoidl.com.sun.star.uno; 
using unoidl.com.sun.star.bridge; 
using unoidl.com.sun.star.frame; 
using unoidl.com.sun.star.text; 
using unoidl.com.sun.star.beans; 
.............................. 
XTextTable odtTbl = (XTextTable) ((XMultiServiceFactory)oodt).createInstance("com.sun.star.text.TextTable"); 
odtTbl.initialize(10, 2); 
XPropertySet xPS = (XPropertySet)odtTbl; 
Object xObj = xPS.getPropertyValue("TableColumnSeparators")**; // << Runtime ERROR** 
TableColumnSeparator[] xSeparators = (TableColumnSeparator[])xObj; 
xSeparators[0].Position = 500; 
xSeparators[1].Position = 5000; 
xPS.setPropertyValue("TableColumnSeparators", new uno.Any(typeof(unoidl.com.sun.star.text.XTextTable),xSeparators)); 

// Runtime ERROR indicates the ; at the end of the Object line, with message of IllegalArgumentException 

現在這只是一種錯誤類型中的所有嘗試組合。根本沒有許多人可以執行,但上面的代碼確實運行直到出錯。

請問在C#中這樣做的正確代碼是什麼?

此外,將O'Writer標題設置爲特定樣式(例如「標題1」)的正確C#代碼是什麼,以便在文檔中查找和打印該樣式?

謝謝。

+0

那麼,沒有人知道呢? – Edunt

回答

0
 unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap(); 
     unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager(); 
     XComponentLoader componentLoader =(XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop"); 
     XComponent xComponent = componentLoader.loadComponentFromURL(
     "private:factory/swriter", //a blank writer document 
     "_blank", 0, //into a blank frame use no searchflag 
     new unoidl.com.sun.star.beans.PropertyValue[0]);//use no additional arguments. 
     //object odtTbl = null; 
     //odtTbl = ((XMultiServiceFactory)xComponent).createInstance("com.sun.star.text.TextTable"); 

     XTextDocument xTextDocument = (unoidl.com.sun.star.text.XTextDocument)xComponent; 
     XText xText = xTextDocument.getText(); 
     XTextCursor xTextCursor = xText.createTextCursor(); 

        XPropertySet xTextCursorProps = (unoidl.com.sun.star.beans.XPropertySet) xTextCursor; 
        XSimpleText xSimpleText = (XSimpleText)xText; 

        XTextCursor xCursor = xSimpleText.createTextCursor(); 

     object objTextTable = null; 
     objTextTable = ((XMultiServiceFactory)xComponent).createInstance("com.sun.star.text.TextTable"); 
     XTextTable xTextTable = (XTextTable)objTextTable; 
     xTextTable.initialize(2,3); 
     xText.insertTextContent(xCursor, xTextTable, false); 


     XPropertySet xPS = (XPropertySet)objTextTable; 
     uno.Any xObj = xPS.getPropertyValue("TableColumnSeparators"); 
     TableColumnSeparator[] xSeparators = (TableColumnSeparator[])xObj.Value; //!!!! xObj.Value 

     xSeparators[0].Position = 2000; 
     xSeparators[1].Position = 3000; 
     xPS.setPropertyValue("TableColumnSeparators", new uno.Any(typeof(TableColumnSeparator[]), xSeparators)); //!!!! TableColumnSeparator[] 
相關問題