Most strings in a workbook have formatting applied at the cell level, that is, the entire string in the cell has the same formatting applied. In these cases, the formatting for the cell is stored in the styles part, and the string for the cell can be shared across the workbook. The following code illustrates the example.
In the above example all three cells will use the same string cached on workbook level.cell1.setCellValue(new XSSFRichTextString("Apache POI")); cell2.setCellValue(new XSSFRichTextString("Apache POI")); cell3.setCellValue(new XSSFRichTextString("Apache POI"));
Some strings in the workbook may have formatting applied at a level that is more granular than the cell level. For instance, specific characters within the string may be bolded, have coloring, italicizing, etc. In these cases, the formatting is stored along with the text in the string table, and is treated as a unique entry in the workbook. The following xml and code snippet illustrate this.
@author Yegor KozlovXSSFRichTextString s1 = new XSSFRichTextString("Apache POI"); s1.applyFont(boldArial); cell1.setCellValue(s1); XSSFRichTextString s2 = new XSSFRichTextString("Apache POI"); s2.applyFont(italicCourier); cell2.setCellValue(s2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|