Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a part of the cell contents to bold using apache poi?

How can i put this string in to a cell using java apache poi?
The string is "Hello world Hello"
As u can see i need to make a part of the text bold?
I'm able to set the entire contents of the cell to bold but not specific parts.
Please help me.

like image 408
Saicharan S M Avatar asked Mar 14 '12 07:03

Saicharan S M


People also ask

How do you make a cell value bold in Apache POI?

HSSFWorkbook hwb=new HSSFWorkbook(); HSSFSheet sheet=hwb. crateSheet("New Sheet"); HssfRow headRow=sheet. createRow((int)0); CellStyle style=headRow. getRowStyle(); Font boldFont=hwb.

How do you make something bold in Java?

To make a text bold create a font bypassing FontWeight. BOLD or, FontWeight. EXTRA_BOLD as the value of the parameter weight and, to make a text italic pass FontPosture. ITALIC as the value of the parameter posture.

How do I wrap text in Apache POI?

Text WrappingCellStyle wrap = wb. createCellStyle(); wrap. setWrapText(true);

How do I change font size in POI?

the POI HSSF Font class has two font size settings methods: setFontHeight(short) - Set the font height in unit's of 1/20th of a point. setFontHeightInPoints(short) - Set the font height in point.


1 Answers

This is probably what you are looking for: http://poi.apache.org/spreadsheet/quick-guide.html#DrawingShapes

Find this in the explanation:

It's possible to use different fonts to style parts of the text in the textbox. Here's how:

HSSFFont font = wb.createFont();
font.setItalic(true);
font.setUnderline(HSSFFont.U_DOUBLE);
HSSFRichTextString string = new HSSFRichTextString("Woo!!!");
string.applyFont(2,5,font);
textbox.setString(string );

This might be useful: http://apache-poi.1045710.n5.nabble.com/Multiple-text-styles-in-Excel-cell-td4922683.html

like image 177
Michael Fernando Avatar answered Oct 28 '22 20:10

Michael Fernando