use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.
the class XSSFBSheetHandler method handleBrtCellIsst.
private void handleBrtCellIsst(byte[] data) {
beforeCellValue(data);
int idx = XSSFBUtils.castToInt(LittleEndian.getUInt(data, XSSFBCellHeader.length));
XSSFRichTextString rtss = new XSSFRichTextString(stringsTable.getEntryAt(idx));
handleCellValue(rtss.getString());
}
use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.
the class TestSharedStringsTable method testCreateNew.
public void testCreateNew() {
SharedStringsTable sst = new SharedStringsTable();
CTRst st;
int idx;
// Check defaults
assertNotNull(sst.getItems());
assertEquals(0, sst.getItems().size());
assertEquals(0, sst.getCount());
assertEquals(0, sst.getUniqueCount());
st = CTRst.Factory.newInstance();
st.setT("Hello, World!");
idx = sst.addEntry(st);
assertEquals(0, idx);
assertEquals(1, sst.getCount());
assertEquals(1, sst.getUniqueCount());
//add the same entry again
idx = sst.addEntry(st);
assertEquals(0, idx);
assertEquals(2, sst.getCount());
assertEquals(1, sst.getUniqueCount());
//and again
idx = sst.addEntry(st);
assertEquals(0, idx);
assertEquals(3, sst.getCount());
assertEquals(1, sst.getUniqueCount());
st = CTRst.Factory.newInstance();
st.setT("Second string");
idx = sst.addEntry(st);
assertEquals(1, idx);
assertEquals(4, sst.getCount());
assertEquals(2, sst.getUniqueCount());
//add the same entry again
idx = sst.addEntry(st);
assertEquals(1, idx);
assertEquals(5, sst.getCount());
assertEquals(2, sst.getUniqueCount());
st = CTRst.Factory.newInstance();
CTRElt r = st.addNewR();
CTRPrElt pr = r.addNewRPr();
//red
pr.addNewColor().setRgb(new byte[] { (byte) 0xFF, 0, 0 });
//bold
pr.addNewI().setVal(true);
//italic
pr.addNewB().setVal(true);
r.setT("Second string");
idx = sst.addEntry(st);
assertEquals(2, idx);
assertEquals(6, sst.getCount());
assertEquals(3, sst.getUniqueCount());
idx = sst.addEntry(st);
assertEquals(2, idx);
assertEquals(7, sst.getCount());
assertEquals(3, sst.getUniqueCount());
//OK. the sst table is filled, check the contents
assertEquals(3, sst.getItems().size());
assertEquals("Hello, World!", new XSSFRichTextString(sst.getEntryAt(0)).toString());
assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(1)).toString());
assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString());
}
use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.
the class TestXSSFChartTitle method testExistingChartWithFormulaTitle.
@Test
public void testExistingChartWithFormulaTitle() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitleFormula.xlsx");
XSSFChart chart = getChartFromWorkbook(wb, "Sheet1");
assertNotNull(chart);
XSSFRichTextString originalTitle = chart.getTitleText();
assertNotNull(originalTitle);
assertEquals("", originalTitle.toString());
String formula = chart.getTitleFormula();
assertNotNull(formula);
assertEquals("Sheet1!$E$1", formula);
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.
the class TestCommentsTable method writeRead.
@Test
public void writeRead() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue(sheet1.hasComments());
assertFalse(sheet2.hasComments());
// Change on comment on sheet 1, and add another into
// sheet 2
Row r5 = sheet1.getRow(4);
Comment cc5 = r5.getCell(2).getCellComment();
cc5.setAuthor("Apache POI");
cc5.setString(new XSSFRichTextString("Hello!"));
Row r2s2 = sheet2.createRow(2);
Cell c1r2s2 = r2s2.createCell(1);
assertNull(c1r2s2.getCellComment());
Drawing<?> dg = sheet2.createDrawingPatriarch();
Comment cc2 = dg.createCellComment(new XSSFClientAnchor());
cc2.setAuthor("Also POI");
cc2.setString(new XSSFRichTextString("A new comment"));
c1r2s2.setCellComment(cc2);
// Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0);
sheet2 = workbook.getSheetAt(1);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
// And check they still have the contents they should do
assertEquals("Apache POI", sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Also POI", sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
assertEquals("Hello!", sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
}
use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.
the class TestXSSFReader method testStrings.
public void testStrings() throws Exception {
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg);
assertEquals(11, r.getSharedStringsTable().getItems().size());
assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
}
Aggregations