Search in sources :

Example 6 with XSSFRichTextString

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());
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString)

Example 7 with XSSFRichTextString

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());
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) CTRElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt)

Example 8 with XSSFRichTextString

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();
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 9 with XSSFRichTextString

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());
}
Also used : Comment(org.apache.poi.ss.usermodel.Comment) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFClientAnchor(org.apache.poi.xssf.usermodel.XSSFClientAnchor) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell) Test(org.junit.Test)

Example 10 with XSSFRichTextString

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());
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Aggregations

XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)17 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)7 Workbook (org.apache.poi.ss.usermodel.Workbook)6 Test (org.junit.Test)5 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)4 Cell (org.apache.poi.ss.usermodel.Cell)3 Row (org.apache.poi.ss.usermodel.Row)3 FileOutputStream (java.io.FileOutputStream)2 CellStyle (org.apache.poi.ss.usermodel.CellStyle)2 CellType (org.apache.poi.ss.usermodel.CellType)2 Comment (org.apache.poi.ss.usermodel.Comment)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 XSSFClientAnchor (org.apache.poi.xssf.usermodel.XSSFClientAnchor)2 SAXException (org.xml.sax.SAXException)2 DataFormatException (com.cubrid.common.ui.cubrid.table.dialog.DataFormatException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 FormulaError (org.apache.poi.ss.usermodel.FormulaError)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1