That is odd indeed. My original reply to your message was based upon some
reaserch Yegor undertook for an HSSFRichTextString bug and his findings are
summed up in this message he posted;

"Quite an interesting bug.

Here is the problem in a nutshell:

For reach text containing N runs Excel saves font the first run in the cell
style and subsequent N-1 runs override the font in the cell style.

Compare two snippets that produce equivalent output:

1. POI approach: 

 HSSFCell hssfCell = row.createCell(idx);
 //rich text consists of two runs
 HSSFRichTextString richString = new HSSFRichTextString( "Bug 47543" );
 richString.applyFont( 0, 4, font1 );
 richString.applyFont( 4, 8, font2 );
 hssfCell.setCellValue( richString );

2. Excel approach

 //create a cell style and assign the first font to it
 HSSFCellStyle style = workbook.createCellStyle();
 style.setFont(font1);

 HSSFCell hssfCell = row.createCell(idx);
 hssfCell.setCellStyle(style);

 //rich text consists of one run overriding the cell style
 HSSFRichTextString richString = new HSSFRichTextString( cellValue );
 richString.applyFont( 4, 8, font2 );
 hssfCell.setCellValue( richString );

It turns out that the way you create HSSFRichTextString cells is important,
(1)
results in Excel crash while (2) always seems to work. 

See Driver2 - a version of the attached Driver program that produces valid
output readable and modifiable by Excel 2003. 

driver2-10000.xls is a sample output of 100x100 grid.

Regards,
Yegor"

So, if you are following Yegors suggested approach - number two from the
message above - it would seem as though you may have uncovered a bug. It is
best to log bugs through Bugzilla but, before you do so, let me take the
time to play with some code to see if I can reproduce the problem. Should be
able to get back to you by the end of today, early tomorrow at the latest.

Yours

Mark B


-- 
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Help-in-setting-underline-tp3352666p3353570.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to