1

我正在尝试在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;

输出:

在此处输入图像描述

4

1 回答 1

0

正如在另一个问题中已经回答的那样- 您必须使用字符属性来获取粗体(或其他属性)文本

于 2015-01-05T19:06:56.573 回答