use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testCreateRow.
public void testCreateRow() {
XWPFDocument doc = new XWPFDocument();
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(table, doc);
assertEquals(3, xtab.getNumberOfRows());
assertNotNull(xtab.getRow(2));
//add a new row
xtab.createRow();
assertEquals(4, xtab.getNumberOfRows());
//check number of cols
assertEquals(2, table.getTrArray(0).sizeOfTcArray());
//check creation of first row
xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testConstructor.
public void testConstructor() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
XWPFTable xtab = new XWPFTable(ctTable, doc);
assertNotNull(xtab);
assertEquals(1, ctTable.sizeOfTrArray());
assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
ctTable = CTTbl.Factory.newInstance();
xtab = new XWPFTable(ctTable, doc, 3, 2);
assertNotNull(xtab);
assertEquals(3, ctTable.sizeOfTrArray());
assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testSetGetHeight.
public void testSetGetHeight() {
XWPFDocument doc = new XWPFDocument();
CTTbl table = CTTbl.Factory.newInstance();
XWPFTable xtab = new XWPFTable(table, doc);
XWPFTableRow row = xtab.createRow();
row.setHeight(20);
assertEquals(20, row.getHeight());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testGetText.
public void testGetText() {
XWPFDocument doc = new XWPFDocument();
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(table, doc);
assertEquals("finally I can write!\n", xtab.getText());
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testSetGetMargins.
public void testSetGetMargins() {
// instantiate the following class so it'll get picked up by
// the XmlBean process and added to the jar file. it's required
// for the following XWPFTable methods.
CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
assertNotNull(ctm);
// create a table
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
XWPFTable table = new XWPFTable(ctTable, doc);
// set margins
table.setCellMargins(50, 50, 250, 450);
// get margin components
int t = table.getCellMarginTop();
assertEquals(50, t);
int l = table.getCellMarginLeft();
assertEquals(50, l);
int b = table.getCellMarginBottom();
assertEquals(250, b);
int r = table.getCellMarginRight();
assertEquals(450, r);
}
Aggregations