I wrote the sample code below with POI 3.9.
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
Font defaultFont = workbook.createFont();
Font formattedFont = workbook.createFont();
formattedFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
formattedFont.setItalic(true);
formattedFont.setUnderline((byte) 1);
XSSFRichTextString richtext = new XSSFRichTextString("Hello, World!");
richtext.applyFont(0, 1, formattedFont); // format the first charactor
of cell
richtext.applyFont(1, richtext.length(), defaultFont);
cell.setCellValue(richtext);
System.out.println(cell.getRichStringCellValue().getString());
// Hello, World!
System.out.println(cell.getRichStringCellValue().getString().charAt(0));
// H
System.out.println(cell.getRichStringCellValue().getFontAtIndex(0).getBold());
// true
System.out.println(cell.getRichStringCellValue().getFontAtIndex(0).getItalic());
// true
System.out.println(cell.getRichStringCellValue().getFontAtIndex(0).getUnderline());
// 1
System.out.println(cell.getRichStringCellValue().getString().charAt(1));
// e
System.out.println(cell.getRichStringCellValue().getFontAtIndex(1).getBold());
// false
System.out.println(cell.getRichStringCellValue().getFontAtIndex(1).getItalic());
// false
System.out.println(cell.getRichStringCellValue().getFontAtIndex(1).getUnderline());
// 0
When I run the above code, it seems that getRichStringCellValue method returns
XSSFRichTextString correctly.
Ryo Yamamoto
-----Original Message-----
From: Aruna [mailto:[email protected]]
Sent: Tuesday, January 14, 2014 1:55 AM
To: [email protected]
Subject: Unable to read the fully formatted text from XSSF
Hi,
I am trying to read the rich text string from .xlsx file using XSSF. But when
the first character of cell is formatted (bold/underline/italic), cell is not
reading in richtextformat. Please help me in this.
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Unable-to-read-the-fully-formatted-text-from-XSSF-tp5714625.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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]