Dgan
Dgan

Reputation: 10295

Insert HTML Text Into OpenOffice Document (.odt) Files

I am Trying to Insert HTML Text Inside Apache Open Office .odt File

I try Statement with Bold as show Below but it is not Working.

Is There I am missing Something ?

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;

Output:

enter image description here

Upvotes: 1

Views: 1369

Answers (1)

ngulam
ngulam

Reputation: 1075

As answered already in the other question - you have to use character properties to get bold (or otherwise attributed) text

Upvotes: 0

Related Questions