Search in sources :

Example 6 with CTRst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.

the class TestCommentsTable method getCellComment.

@Test
public void getCellComment() throws Exception {
    CommentsTable sheetComments = new CommentsTable();
    CTComments comments = sheetComments.getCTComments();
    CTCommentList commentList = comments.getCommentList();
    // Create 2 comments for A1 and A" cells
    CTComment comment0 = commentList.insertNewComment(0);
    comment0.setRef("A1");
    CTRst ctrst0 = CTRst.Factory.newInstance();
    ctrst0.setT(TEST_A1_TEXT);
    comment0.setText(ctrst0);
    CTComment comment1 = commentList.insertNewComment(0);
    comment1.setRef("A2");
    CTRst ctrst1 = CTRst.Factory.newInstance();
    ctrst1.setT(TEST_A2_TEXT);
    comment1.setText(ctrst1);
    // test finding the right comment for a cell
    assertSame(comment0, sheetComments.getCTComment(new CellAddress("A1")));
    assertSame(comment1, sheetComments.getCTComment(new CellAddress("A2")));
    assertNull(sheetComments.getCTComment(new CellAddress("A3")));
}
Also used : CTCommentList(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList) CellAddress(org.apache.poi.ss.util.CellAddress) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) CTComments(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments) Test(org.junit.Test)

Example 7 with CTRst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.

the class TestXSSFRichTextString method testCreate.

public void testCreate() {
    XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
    assertEquals("Apache POI", rt.getString());
    assertEquals(false, rt.hasFormatting());
    CTRst st = rt.getCTRst();
    assertTrue(st.isSetT());
    assertEquals("Apache POI", st.getT());
    assertEquals(false, rt.hasFormatting());
    rt.append(" is cool stuff");
    assertEquals(2, st.sizeOfRArray());
    assertFalse(st.isSetT());
    assertEquals("Apache POI is cool stuff", rt.getString());
    assertEquals(false, rt.hasFormatting());
}
Also used : CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)

Example 8 with CTRst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.

the class TestXSSFRichTextString method testClearFormatting.

public void testClearFormatting() {
    XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
    assertEquals("Apache POI", rt.getString());
    assertEquals(false, rt.hasFormatting());
    rt.clearFormatting();
    CTRst st = rt.getCTRst();
    assertTrue(st.isSetT());
    assertEquals("Apache POI", rt.getString());
    assertEquals(0, rt.numFormattingRuns());
    assertEquals(false, rt.hasFormatting());
    XSSFFont font = new XSSFFont();
    font.setBold(true);
    rt.applyFont(7, 10, font);
    assertEquals(2, rt.numFormattingRuns());
    assertEquals(true, rt.hasFormatting());
    rt.clearFormatting();
    assertEquals("Apache POI", rt.getString());
    assertEquals(0, rt.numFormattingRuns());
    assertEquals(false, rt.hasFormatting());
}
Also used : CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)

Example 9 with CTRst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.

the class TestXSSFRichTextString method testApplyFont_lowlevel.

public void testApplyFont_lowlevel() {
    CTRst st = CTRst.Factory.newInstance();
    String text = "Apache Software Foundation";
    XSSFRichTextString str = new XSSFRichTextString(text);
    assertEquals(26, text.length());
    st.addNewR().setT(text);
    TreeMap<Integer, CTRPrElt> formats = str.getFormatMap(st);
    assertEquals(1, formats.size());
    assertEquals(26, (int) formats.firstKey());
    assertNull(formats.get(formats.firstKey()));
    CTRPrElt fmt1 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 0, 6, fmt1);
    assertEquals(2, formats.size());
    assertEquals("[6, 26]", formats.keySet().toString());
    Object[] runs1 = formats.values().toArray();
    assertSame(fmt1, runs1[0]);
    assertSame(null, runs1[1]);
    CTRPrElt fmt2 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 7, 15, fmt2);
    assertEquals(4, formats.size());
    assertEquals("[6, 7, 15, 26]", formats.keySet().toString());
    Object[] runs2 = formats.values().toArray();
    assertSame(fmt1, runs2[0]);
    assertSame(null, runs2[1]);
    assertSame(fmt2, runs2[2]);
    assertSame(null, runs2[3]);
    CTRPrElt fmt3 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 6, 7, fmt3);
    assertEquals(4, formats.size());
    assertEquals("[6, 7, 15, 26]", formats.keySet().toString());
    Object[] runs3 = formats.values().toArray();
    assertSame(fmt1, runs3[0]);
    assertSame(fmt3, runs3[1]);
    assertSame(fmt2, runs3[2]);
    assertSame(null, runs3[3]);
    CTRPrElt fmt4 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 0, 7, fmt4);
    assertEquals(3, formats.size());
    assertEquals("[7, 15, 26]", formats.keySet().toString());
    Object[] runs4 = formats.values().toArray();
    assertSame(fmt4, runs4[0]);
    assertSame(fmt2, runs4[1]);
    assertSame(null, runs4[2]);
    CTRPrElt fmt5 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 0, 26, fmt5);
    assertEquals(1, formats.size());
    assertEquals("[26]", formats.keySet().toString());
    Object[] runs5 = formats.values().toArray();
    assertSame(fmt5, runs5[0]);
    CTRPrElt fmt6 = CTRPrElt.Factory.newInstance();
    str.applyFont(formats, 15, 26, fmt6);
    assertEquals(2, formats.size());
    assertEquals("[15, 26]", formats.keySet().toString());
    Object[] runs6 = formats.values().toArray();
    assertSame(fmt5, runs6[0]);
    assertSame(fmt6, runs6[1]);
    str.applyFont(formats, 0, 26, null);
    assertEquals(1, formats.size());
    assertEquals("[26]", formats.keySet().toString());
    Object[] runs7 = formats.values().toArray();
    assertSame(null, runs7[0]);
    str.applyFont(formats, 15, 26, fmt6);
    assertEquals(2, formats.size());
    assertEquals("[15, 26]", formats.keySet().toString());
    Object[] runs8 = formats.values().toArray();
    assertSame(null, runs8[0]);
    assertSame(fmt6, runs8[1]);
    str.applyFont(formats, 15, 26, fmt5);
    assertEquals(2, formats.size());
    assertEquals("[15, 26]", formats.keySet().toString());
    Object[] runs9 = formats.values().toArray();
    assertSame(null, runs9[0]);
    assertSame(fmt5, runs9[1]);
    str.applyFont(formats, 2, 20, fmt6);
    assertEquals(3, formats.size());
    assertEquals("[2, 20, 26]", formats.keySet().toString());
    Object[] runs10 = formats.values().toArray();
    assertSame(null, runs10[0]);
    assertSame(fmt6, runs10[1]);
    assertSame(fmt5, runs10[2]);
    str.applyFont(formats, 22, 24, fmt4);
    assertEquals(5, formats.size());
    assertEquals("[2, 20, 22, 24, 26]", formats.keySet().toString());
    Object[] runs11 = formats.values().toArray();
    assertSame(null, runs11[0]);
    assertSame(fmt6, runs11[1]);
    assertSame(fmt5, runs11[2]);
    assertSame(fmt4, runs11[3]);
    assertSame(fmt5, runs11[4]);
    str.applyFont(formats, 0, 10, fmt1);
    assertEquals(5, formats.size());
    assertEquals("[10, 20, 22, 24, 26]", formats.keySet().toString());
    Object[] runs12 = formats.values().toArray();
    assertSame(fmt1, runs12[0]);
    assertSame(fmt6, runs12[1]);
    assertSame(fmt5, runs12[2]);
    assertSame(fmt4, runs12[3]);
    assertSame(fmt5, runs12[4]);
}
Also used : CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt)

Example 10 with CTRst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst in project poi by apache.

the class TestXSSFRichTextString method testPreserveSpaces.

/**
     * make sure we insert xml:space="preserve" attribute
     * if a string has leading or trailing white spaces
     */
public void testPreserveSpaces() {
    XSSFRichTextString rt = new XSSFRichTextString("Apache");
    CTRst ct = rt.getCTRst();
    STXstring xs = ct.xgetT();
    assertEquals("<xml-fragment>Apache</xml-fragment>", xs.xmlText());
    rt.setString("  Apache");
    assertEquals("<xml-fragment xml:space=\"preserve\">  Apache</xml-fragment>", xs.xmlText());
    rt.append(" POI");
    rt.append(" ");
    assertEquals("  Apache POI ", rt.getString());
    assertEquals("<xml-fragment xml:space=\"preserve\">  Apache</xml-fragment>", rt.getCTRst().getRArray(0).xgetT().xmlText());
    assertEquals("<xml-fragment xml:space=\"preserve\"> POI</xml-fragment>", rt.getCTRst().getRArray(1).xgetT().xmlText());
    assertEquals("<xml-fragment xml:space=\"preserve\"> </xml-fragment>", rt.getCTRst().getRArray(2).xgetT().xmlText());
}
Also used : STXstring(org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)

Aggregations

CTRst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)14 CTRPrElt (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt)5 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3 CTRElt (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 BaseTestXCell (org.apache.poi.ss.usermodel.BaseTestXCell)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 CellAddress (org.apache.poi.ss.util.CellAddress)1 SharedStringsTable (org.apache.poi.xssf.model.SharedStringsTable)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlException (org.apache.xmlbeans.XmlException)1 CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)1