use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid in project poi by apache.
the class HeaderFooterTable method main.
public static void main(String[] args) throws IOException {
XWPFDocument doc = new XWPFDocument();
// Create a header with a 1 row, 3 column table
// changes made for issue 57366 allow a new header or footer
// to be created empty. This is a change. You will have to add
// either a paragraph or a table to the header or footer for
// the document to be considered valid.
XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
XWPFTable tbl = hdr.createTable(1, 3);
// Set the padding around text in the cells to 1/10th of an inch
int pad = (int) (.1 * 1440);
tbl.setCellMargins(pad, pad, pad, pad);
// Set table width to 6.5 inches in 1440ths of a point
tbl.setWidth((int) (6.5 * 1440));
// Can not yet set table or cell width properly, tables default to
// autofit layout, and this requires fixed layout
CTTbl ctTbl = tbl.getCTTbl();
CTTblPr ctTblPr = ctTbl.addNewTblPr();
CTTblLayoutType layoutType = ctTblPr.addNewTblLayout();
layoutType.setType(STTblLayoutType.FIXED);
// Now set up a grid for the table, cells will fit into the grid
// Each cell width is 3120 in 1440ths of an inch, or 1/3rd of 6.5"
BigInteger w = new BigInteger("3120");
CTTblGrid grid = ctTbl.addNewTblGrid();
for (int i = 0; i < 3; i++) {
CTTblGridCol gridCol = grid.addNewGridCol();
gridCol.setW(w);
}
// Add paragraphs to the cells
XWPFTableRow row = tbl.getRow(0);
XWPFTableCell cell = row.getCell(0);
XWPFParagraph p = cell.getParagraphArray(0);
XWPFRun r = p.createRun();
r.setText("header left cell");
cell = row.getCell(1);
p = cell.getParagraphArray(0);
r = p.createRun();
r.setText("header center cell");
cell = row.getCell(2);
p = cell.getParagraphArray(0);
r = p.createRun();
r.setText("header right cell");
// Create a footer with a Paragraph
XWPFFooter ftr = doc.createFooter(HeaderFooterType.DEFAULT);
p = ftr.createParagraph();
r = p.createRun();
r.setText("footer text");
OutputStream os = new FileOutputStream(new File("headertable.docx"));
doc.write(os);
doc.close();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid in project poi by apache.
the class XWPFTable method createEmptyTable.
private void createEmptyTable(CTTbl table) {
// MINIMUM ELEMENTS FOR A TABLE
table.addNewTr().addNewTc().addNewP();
CTTblPr tblpro = table.addNewTblPr();
tblpro.addNewTblW().setW(new BigInteger("0"));
tblpro.getTblW().setType(STTblWidth.AUTO);
// layout
// tblpro.addNewTblLayout().setType(STTblLayoutType.AUTOFIT);
// borders
CTTblBorders borders = tblpro.addNewTblBorders();
borders.addNewBottom().setVal(STBorder.SINGLE);
borders.addNewInsideH().setVal(STBorder.SINGLE);
borders.addNewInsideV().setVal(STBorder.SINGLE);
borders.addNewLeft().setVal(STBorder.SINGLE);
borders.addNewRight().setVal(STBorder.SINGLE);
borders.addNewTop().setVal(STBorder.SINGLE);
/*
* CTTblGrid tblgrid=table.addNewTblGrid();
* tblgrid.addNewGridCol().setW(new BigInteger("2000"));
*/
getRows();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid in project poi by apache.
the class TestXWPFTable method testTblGrid.
public void testTblGrid() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
CTTblGrid cttblgrid = ctTable.addNewTblGrid();
cttblgrid.addNewGridCol().setW(new BigInteger("123"));
cttblgrid.addNewGridCol().setW(new BigInteger("321"));
XWPFTable xtab = new XWPFTable(ctTable, doc);
assertEquals(123, xtab.getCTTbl().getTblGrid().getGridColArray(0).getW().intValue());
assertEquals(321, xtab.getCTTbl().getTblGrid().getGridColArray(1).getW().intValue());
}
Aggregations