2011-01-29 8 views
0

私はOO WriterドキュメントをC#で作成しています。C#を使用したOpenOffice Writerの問題

任意の助けいただければ幸いです - 私はもはや私が来たりつもりですか知っている、私は非常に多くのバリエーションを試していない....

C#を使用して、誰もが成功し、次の仕事に持っていますか?私はちょうど2列の単純なテーブルを持って、列の幅を異なる値に設定したい(この段階での実際の値は重要ではない - 同じ幅ではない)。

このコードは、列の幅をどのように行うかの例として示したさまざまなWebソースから適合しています。私はそれを働かせることができません....

//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 

これは、試みのすべての組み合わせのうちの1つのタイプのエラーです。まったく実行が許可されていませんが、上記のコードは実際にエラーが発生するまで実行されました。

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[] 
関連する問題