Search in sources :

Example 11 with CTTbl

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl 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());
}
Also used : CTTblGrid(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid) BigInteger(java.math.BigInteger) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Example 12 with CTTbl

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.

the class TestXWPFTable method testSetGetRowBandSize.

public void testSetGetRowBandSize() {
    XWPFDocument doc = new XWPFDocument();
    CTTbl ctTable = CTTbl.Factory.newInstance();
    XWPFTable table = new XWPFTable(ctTable, doc);
    table.setRowBandSize(12);
    int sz = table.getRowBandSize();
    assertEquals(12, sz);
}
Also used : CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Example 13 with CTTbl

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.

the class TestXWPFTable method testSetGetVBorders.

public void testSetGetVBorders() {
    // create a table
    XWPFDocument doc = new XWPFDocument();
    CTTbl ctTable = CTTbl.Factory.newInstance();
    XWPFTable table = new XWPFTable(ctTable, doc);
    // set inside vertical border
    table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
    // get inside vertical border components
    XWPFBorderType bt = table.getInsideVBorderType();
    assertEquals(XWPFBorderType.DOUBLE, bt);
    int sz = table.getInsideVBorderSize();
    assertEquals(4, sz);
    int sp = table.getInsideVBorderSpace();
    assertEquals(0, sp);
    String clr = table.getInsideVBorderColor();
    assertEquals("00FF00", clr);
}
Also used : XWPFBorderType(org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Example 14 with CTTbl

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.

the class TestXWPFTable method testSetGetColBandSize.

public void testSetGetColBandSize() {
    XWPFDocument doc = new XWPFDocument();
    CTTbl ctTable = CTTbl.Factory.newInstance();
    XWPFTable table = new XWPFTable(ctTable, doc);
    table.setColBandSize(16);
    int sz = table.getColBandSize();
    assertEquals(16, sz);
}
Also used : CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)

Example 15 with CTTbl

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project Gargoyle by callakrsos.

the class MSWord method addToTable.

/**
	 * 테이블을 추가한다.
	 *
	 * List의 로우는 각 행을 의미. TreeSet은 테이블 컬럼Index 데이터를 의미.
	 *
	 * @param list
	 */
public XWPFTable addToTable(List<List<String>> list, ITableCustomProperty property) /*
																						* ,
																						* ThFunction
																						* <
																						* ,
																						* U
																						* ,
																						* V
																						* ,
																						* R
																						* >
																						*/
{
    if (list == null || list.isEmpty()) {
        return null;
    }
    // -- OR --
    // open an existing empty document with styles already defined
    // XWPFDocument doc = new XWPFDocument(new
    // FileInputStream("base_document.docx"));
    int rowSize = list.size();
    int colSize = list.get(0).size();
    XWPFTable table = doc.createTable(rowSize, colSize);
    // Set the table style. If the style is not defined, the table style
    // will become "Normal".
    {
        CTTblPr tblPr = table.getCTTbl().getTblPr();
        CTString styleStr = tblPr.addNewTblStyle();
        styleStr.setVal("StyledTable");
    }
    /* Table Width조절을 위한 작업 */
    {
        CTTbl ctTbl = table.getCTTbl();
        CTTblPr tblPr = ctTbl.getTblPr();
        CTTblWidth tblW = tblPr.getTblW();
        // 화면에 WIDTH를 딱 맞춤.
        tblW.setW(BigInteger.valueOf(5000));
        tblW.setType(STTblWidth.PCT);
    }
    // Get a list of the rows in the table
    // List<XWPFTableRow> rows = table.getRows();
    int rowCt = 0;
    int colCt = 0;
    for (List<String> set : list) {
        XWPFTableRow row = table.getRow(rowCt);
        CTTrPr trPr = row.getCtRow().addNewTrPr();
        // set row height; units = twentieth of a point, 360 = 0.25"
        CTHeight ht = trPr.addNewTrHeight();
        ht.setVal(BigInteger.valueOf(/* 360 */
        240));
        // get the cells in this row
        List<XWPFTableCell> cells = row.getTableCells();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            if (cells.size() == colCt) {
                row.createCell();
            }
            // get a table cell properties element (tcPr)
            XWPFTableCell cell = cells.get(colCt);
            CTTcPr tcpr = cell.getCTTc().addNewTcPr();
            // set vertical alignment to "center"
            CTVerticalJc va = tcpr.addNewVAlign();
            va.setVal(STVerticalJc.CENTER);
            // create cell color element
            CTShd ctshd = tcpr.addNewShd();
            ctshd.setColor("auto");
            ctshd.setVal(STShd.CLEAR);
            if (rowCt == 0) {
                // header row
                ctshd.setFill("FFFE99");
            } else if (rowCt % 2 == 0) {
                // even row
                // FFFFFF : 흰색
                ctshd.setFill("D3DFEE");
            } else {
                // odd row
                ctshd.setFill("EDF2F8");
            }
            // get 1st paragraph in cell's paragraph list
            XWPFParagraph para = cell.getParagraphs().get(0);
            // create a run to contain the content
            // 2015.3.17 fix
            // XWPFRun rh = para.createRun();
            KrXWPFRun rh = new KrXWPFRun(para.createRun());
            rh.setFontFamily(fontName);
            // style cell as desired
            if (colCt == colSize - 1) {
                // last column is 10pt Courier
                rh.setFontSize(DEFAULT_FONT_SIZE);
            }
            String content = it.next();
            if (rowCt == 0) {
                // header row
                rh.setText(content);
                rh.setFontSize(H5);
                rh.setBold(true);
                para.setAlignment(ParagraphAlignment.CENTER);
            } else if (rowCt % 2 == 0) {
                // even row
                addTableText(rh, content);
                rh.setSubscript(VerticalAlign.BASELINE);
                para.setAlignment(ParagraphAlignment.LEFT);
            } else {
                addTableText(rh, content);
                // odd row
                rh.setSubscript(VerticalAlign.BASELINE);
                para.setAlignment(ParagraphAlignment.LEFT);
            }
            colCt++;
        }
        // for cell
        colCt = 0;
        rowCt++;
    }
    if (property != null) {
        property.doCustom(table);
    }
    return table;
}
Also used : CTTblWidth(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth) XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) XWPFTable(org.apache.poi.xwpf.usermodel.XWPFTable) CTTblPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr) CTShd(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd) CTString(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString) CTTrPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow) CTHeight(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight) CTString(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTVerticalJc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc) CTTcPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr)

Aggregations

CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)31 XmlCursor (org.apache.xmlbeans.XmlCursor)14 XmlObject (org.apache.xmlbeans.XmlObject)13 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)11 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)5 BigInteger (java.math.BigInteger)4 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3 CTTblPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr)3 InputStream (java.io.InputStream)2 POIXMLException (org.apache.poi.POIXMLException)2 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)2 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)2 XWPFBorderType (org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType)2 XWPFTableCell (org.apache.poi.xwpf.usermodel.XWPFTableCell)2 XWPFTableRow (org.apache.poi.xwpf.usermodel.XWPFTableRow)2 CTTblBorders (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders)2 CTTblGrid (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1