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.
HSSFWorkbook hwb=new HSSFWorkbook(); HSSFSheet sheet=hwb. crateSheet("New Sheet"); HssfRow headRow=sheet. createRow((int)0); CellStyle style=headRow. getRowStyle(); Font boldFont=hwb.
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.
Text WrappingCellStyle wrap = wb. createCellStyle(); wrap. setWrapText(true);
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With