将HTML文本插入OpenOffice文档(.odt)文件

时间:2015-01-05 10:27:54

标签: c# openoffice.org openoffice-writer openoffice-api

我正在尝试在 Apache Open Office .odt文件中插入HTML文本

我尝试使用Bold语句,如下所示,但它不起作用。

我缺少什么吗?

XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
        XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();

  XComponentLoader oDesk = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
    string url = @"private:factory/swriter";
PropertyValue[] propVals = new PropertyValue[0];

XComponent oDoc = oDesk.loadComponentFromURL(url, "_blank", 0, propVals);
string docText = "<b>This will</b> be my first paragraph.\n\r";
docText += "This will be my second paragraph.\n\r";
((XTextDocument)oDoc).getText().setString(docText);
string fileName = @"C:\test.odt";
fileName = "file:///" + fileName.Replace(@"\", "/");
((XStorable)oDoc).storeAsURL(fileName, propVals);
((XComponent)oDoc).dispose();
oDoc = null;

输出:

enter image description here

1 个答案:

答案 0 :(得分:0)

正如the other question中已经回答的那样 - 您必须使用字符属性来获取粗体(或以其他方式归属)文本