POI prevaluation error with table

I have a problem rendering MS Word tables in my Alfresco Share. Tables are always displayed outside the margin, I think this is a problem with OpenOffice (default set in Alfresco Share). Please attach a picture of the error and my source code:

int nCols = 4;
XWPFTable table = doc.createTable(numeroPropuestas+1, nCols); // se le suma uno para aΓ±adr la cabecera
// Set the table style. If the style is not defined, the table style
// will become "Normal".
CTTblPr tblPr = table.getCTTbl().getTblPr();

CTTblWidth width = table.getCTTbl().addNewTblPr().addNewTblW();
width.setType(STTblWidth.DXA);
width.setW(BigInteger.valueOf(9072));

CTString styleStr = tblPr.addNewTblStyle();
styleStr.setVal("StyledTable");

// Get a list of the rows in the table
List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
int filasArrays = 0;
for (XWPFTableRow row : rows) {

    //
    ArrayList<String> alFila = new ArrayList<String>();
    if (rowCt != 0){
        alFila.add(lDescripcion.get(filasArrays));
        alFila.add(lTipo.get(filasArrays));
        alFila.add(lClasificacion.get(filasArrays));
        alFila.add(lResponsable.get(filasArrays));

        filasArrays ++;
    }
    // get table row properties (trPr)
    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));

    // get the cells in this row
    List<XWPFTableCell> cells = row.getTableCells();
    // add content to each cell
    for (XWPFTableCell cell : cells) {
        // get a table cell properties element (tcPr)
        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("A7BFDE");
        }
        else if (rowCt % 2 == 0) {
            // even row
            ctshd.setFill("D3DFEE");
        }
        else {
            // odd row
            ctshd.setFill("EDF2F8");
        }

        // get 1st paragraph in cell paragraph list
        XWPFParagraph para = cell.getParagraphs().get(0);
        // create a run to contain the content
        XWPFRun rh = para.createRun();
        // style cell as desired
        if (colCt == nCols - 1) {
            // last column is 10pt Courier
            rh.setFontSize(10);
            rh.setFontFamily("Courier");
        }
        if (rowCt == 0) {
            // header row
            rh.setText(cabecera[colCt]);
            rh.setBold(true);
            para.setAlignment(ParagraphAlignment.CENTER);
        }
        else if (rowCt % 2 == 0) {
            // even row
            rh.setText( alFila.get(colCt) );
            para.setAlignment(ParagraphAlignment.LEFT);
        }
        else {
            // odd row
            rh.setText(alFila.get(colCt));
            para.setAlignment(ParagraphAlignment.LEFT);
        }
        colCt++;
    } // for cell
    colCt = 0;
    rowCt++;
} // for row

      

Table out of the margin

+3


source to share





All Articles