Ejemplo n.º 1
0
  public void testGetSetColDefaultStyle() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    ColumnHelper columnHelper = sheet.getColumnHelper();

    // POI column 3, OOXML column 4
    CTCol col = columnHelper.getOrCreateColumn1Based(4, false);

    assertNotNull(col);
    assertNotNull(columnHelper.getColumn(3, false));
    columnHelper.setColDefaultStyle(3, 2);
    assertEquals(2, columnHelper.getColDefaultStyle(3));
    assertEquals(-1, columnHelper.getColDefaultStyle(4));
    StylesTable stylesTable = workbook.getStylesSource();
    CTXf cellXf = CTXf.Factory.newInstance();
    cellXf.setFontId(0);
    cellXf.setFillId(0);
    cellXf.setBorderId(0);
    cellXf.setNumFmtId(0);
    cellXf.setXfId(0);
    stylesTable.putCellXf(cellXf);
    CTCol col_2 = ctWorksheet.getColsArray(0).addNewCol();
    col_2.setMin(10);
    col_2.setMax(12);
    col_2.setStyle(1);
    assertEquals(1, columnHelper.getColDefaultStyle(11));
    XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null);
    columnHelper.setColDefaultStyle(11, cellStyle);
    assertEquals(0, col_2.getStyle());
    assertEquals(1, columnHelper.getColDefaultStyle(10));
  }
Ejemplo n.º 2
0
  /**
   * generated <code><col><code> tags.
   * @param sheet
   * @param table container.
   */
  private void generateColumns(XSSFSheet sheet, Element table) {
    List<CTCols> colsList = sheet.getCTWorksheet().getColsList();
    MathContext mc = new MathContext(3);
    for (CTCols cols : colsList) {
      long oldLevel = 1;
      for (CTCol col : cols.getColArray()) {
        while (true) {
          if (oldLevel == col.getMin()) {
            break;
          }
          Element column = htmlDocumentFacade.createTableColumn();
          //					htmlDocumentFacade.addStyleClass(column, "col", "width:2cm;");
          column.setAttribute("style", "width:2cm;");
          table.appendChild(column);
          oldLevel++;
        }
        Element column = htmlDocumentFacade.createTableColumn();
        String width =
            new BigDecimal(sheet.getColumnWidth(Long.bitCount(oldLevel)) / 1440.0, mc).toString();
        column.setAttribute("style", "width:".concat(width).concat("cm;"));
        table.appendChild(column);

        oldLevel++;
      }
    }
  }
Ejemplo n.º 3
0
 private void setWorksheetOutlineLevelRow() {
   CTWorksheet ct = _sh.getCTWorksheet();
   CTSheetFormatPr pr = ct.isSetSheetFormatPr() ? ct.getSheetFormatPr() : ct.addNewSheetFormatPr();
   if (outlineLevelRow > 0) pr.setOutlineLevelRow((short) outlineLevelRow);
 }