コード例 #1
0
  public void testGetText() {
    CTTbl table = CTTbl.Factory.newInstance();
    CTRow row = table.addNewTr();
    CTTc cell = row.addNewTc();
    CTP paragraph = cell.addNewP();
    CTR run = paragraph.addNewR();
    CTText text = run.addNewT();
    text.setStringValue("finally I can write!");

    XWPFTable xtab = new XWPFTable(null, table);
    assertEquals("finally I can write!\n", xtab.getText());
  }
コード例 #2
0
  public void testCreateRow() {
    CTTbl table = CTTbl.Factory.newInstance();
    CTRow r1 = table.addNewTr();
    r1.addNewTc().addNewP();
    r1.addNewTc().addNewP();
    CTRow r2 = table.addNewTr();
    r2.addNewTc().addNewP();
    r2.addNewTc().addNewP();
    CTRow r3 = table.addNewTr();
    r3.addNewTc().addNewP();
    r3.addNewTc().addNewP();

    XWPFTable xtab = new XWPFTable(null, table);
    assertEquals(3, xtab.getNumberOfRows());
    assertNotNull(xtab.getRow(2));

    // add a new row
    xtab.createRow();

    // check number of cols
    assertEquals(2, table.getTrArray(0).sizeOfTcArray());

    // check creation of first row
    xtab = new XWPFTable(null, CTTbl.Factory.newInstance());
    assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
  }