Ejemplo n.º 1
0
 /**
  * Returns number of column if the XWPF table by using the declared cell (which can declare
  * gridSpan) from the first row.
  *
  * @param table
  * @return
  */
 public static int getNumberOfColumns(XWPFTableRow row) {
   if (row == null) {
     return 0;
   }
   // Get first row to know if there is cell which have gridSpan to compute
   // columns number.
   int nbCols = 0;
   List<XWPFTableCell> tableCellsOffFirstRow = row.getTableCells();
   for (XWPFTableCell tableCellOffFirstRow : tableCellsOffFirstRow) {
     CTDecimalNumber gridSpan = getGridSpan(tableCellOffFirstRow);
     if (gridSpan != null) {
       nbCols += gridSpan.getVal().intValue();
     } else {
       nbCols += 1;
     }
   }
   return nbCols;
 }
Ejemplo n.º 2
0
  private static Collection<Float> computeColWidths(XWPFTableRow row) {
    List<Float> colWidths = new ArrayList<Float>();
    List<XWPFTableCell> cells = row.getTableCells();
    for (XWPFTableCell cell : cells) {

      // Width
      CTTblWidth width = getWidth(cell);
      if (width != null) {
        int nb = 1;
        CTDecimalNumber gridSpan = getGridSpan(cell);
        TableWidth tableCellWidth = getTableWidth(cell);
        if (gridSpan != null) {
          nb = gridSpan.getVal().intValue();
        }
        for (int i = 0; i < nb; i++) {
          colWidths.add(tableCellWidth.width / nb);
        }
      }
    }
    return colWidths;
  }
Ejemplo n.º 3
0
  private static int getNbColumnsToIgnore(XWPFTableRow row, boolean before) {
    CTTrPr trPr = row.getCtRow().getTrPr();
    if (trPr == null) {
      return 0;
    }

    List<CTDecimalNumber> gridBeforeAfters =
        before ? trPr.getGridBeforeList() : trPr.getGridAfterList();
    if (gridBeforeAfters == null || gridBeforeAfters.size() < 1) {
      return 0;
    }
    int nbColumns = 0;
    BigInteger val = null;
    for (CTDecimalNumber gridBeforeAfter : gridBeforeAfters) {
      val = gridBeforeAfter.getVal();
      if (val != null) {
        nbColumns += val.intValue();
      }
    }

    return nbColumns;
  }