0

C# で OO 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 の見出しを特定のスタイル (「Heading 1」など) に設定して、ドキュメントでそのスタイルのように表示および印刷するための正しい C# コードは何ですか?

ありがとうございました。

4

1 に答える 1

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[]
于 2011-02-09T11:54:12.817 に答える