Free Support Forum - aspose.com

Setting individual characters to Bold undoes other formatting

I have a block of 7x4 merged cells into which I insert text: 3 sentences separated with hard line returns (’\n’). I have set the worksheet’s default style to Tahoma, font size 9. After inserting the text, I also apply a style whose attributes include Tahoma and font size 9.

If I export and view the results, they are correct. However - I then wish to set the first word of each of the three sentences to be bold using a command of the form: range[0, 0].Characters(x, y).Font.IsBold = true. If I do this, the specified letters all become bold, but then when the sheet is exported, the font is Cambria 10. When I highlight the merged cell, it shows in the Excel toolbar that it is Tahoma 9, but it is not. If I right-click the cell in Excel and select “Format Cells…”, it shows there that the font is actually Cambria (which seems to be an Excel 2007 default), and it does not recognize a size, though it is in fact size 10. I have also tried setting the style attributes again after applying the boldness, to no avail.

What is going on, and how can I have both the style I desire and bold certain words in my text?

Thank you,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

I tested you scenario with the latest version of Aspose.Cells and it works fine. Please download and try the latest version from the following location and if you still face any problem, please share your sample code and generated file and we will check it soon.

http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/entry215207.aspx

Following is my sample code:

Workbook workbook = new Workbook();

Style style = workbook.Styles[workbook.Styles.Add()];

style.Font.Name = "Tahoma";

style.Font.Size = 10;

workbook.DefaultStyle = style;

Worksheet sheet = workbook.Worksheets[0];

sheet.Cells.Merge(0,0,7,4);

sheet.Cells[0, 0].PutValue("Test For Font Setting \n Default Font Tahoma \n Test For New Font");

sheet.Cells[0, 0].Style.IsTextWrapped = true;

sheet.Cells[0, 0].Characters(0, 4).Font.IsBold = true;

workbook.Save("C:\\Test_Temp\\book1.xls");

Thank You & Best Regards,