/** * Get the cell style by index. * * @param idx * @return */ public CTCellStyle getStyleByIndex(long idx) { if (this.getJaxbElement().getCellStyles()!=null) { return this.getJaxbElement().getCellStyles().getCellStyle().get((int)idx); } return null; }
/** * Cells in the Sheet Part reference the xf (data format) records by zero-based index. * * @param idx * @return */ public CTXf getXfByIndex(long idx) { if (this.getJaxbElement().getCellXfs()!=null) { return this.getJaxbElement().getCellXfs().getXf().get( (int)idx); } return null; }
/** * Create an instance of {@link CTStylesheet } * */ public CTStylesheet createCTStylesheet() { return new CTStylesheet(); }
borders.getBorder().add(generateBorder(factory, borderPr)); borders.setCount(2L); stylesheet.setBorders(borders); stylesheet.setCellXfs(new CTCellXfs()); stylesheet.getCellXfs().setCount(2L); CTCellAlignment cellAlignment = new CTCellAlignment(); cellAlignment.setWrapText(true); stylesheet.getCellXfs().getXf().add(generateCTXf(0l, 0l, null, 0l, 0l, cellAlignment, null)); stylesheet.getCellXfs().getXf().add(generateCTXf(1l, 0l, null, 0l, 0l, cellAlignment, true)); stylesheet.setCellStyles(new CTCellStyles()); stylesheet.getCellStyles().setCount(1L); CTCellStyle cellStyle = new CTCellStyle(); cellStyle.setName("myStyle"); cellStyle.setXfId(0L); cellStyle.setCustomBuiltin(true); stylesheet.getCellStyles().getCellStyle().add(cellStyle); stylesheet.setCellStyleXfs(new CTCellStyleXfs()); stylesheet.getCellStyleXfs().setCount(1L); stylesheet.getCellStyleXfs().getXf().add(generateCTXf(0l, null, null, 0l, 0l, null, null)); stylesheet.setFills(factory.createCTFills()); CTFill fill = factory.createCTFill(); CTPatternFill ctPatternFill = new CTPatternFill(); ctPatternFill.setPatternType(STPatternType.NONE); fill.setPatternFill(ctPatternFill);
public StyleSheet(CTStylesheet ctStylesheet) { this.ctStylesheet = ctStylesheet; CTCellStyles ctCellStyles = ctStylesheet.getCellStyles(); CTCellStyleXfs ctCellStyleXfs = ctStylesheet.getCellStyleXfs(); CTCellXfs ctCellXfs = ctStylesheet.getCellXfs(); if (ctCellStyles != null && ctCellStyleXfs != null) { for (CTCellStyle ctCellStyle : ctCellStyles.getCellStyle()) {
public void saveStyle() { if (!newCellXfs.isEmpty()) { CTCellXfs ctCellXfs = ctStylesheet.getCellXfs(); if (ctCellXfs == null) { ctCellXfs = new CTCellXfs(); ctStylesheet.setCellXfs(ctCellXfs); } ctCellXfs.setCount((long) cellXfsIndex.size()); List<CTXf> xfs = ctCellXfs.getXf(); for (CellXfs cellXfs : newCellXfs) { CTXf ctXf = new CTXf(); ctXf.setNumFmtId(cellXfs.getNumFmtId()); ctXf.setFontId(cellXfs.getFontId()); ctXf.setFillId(cellXfs.getFillId()); ctXf.setBorderId(cellXfs.getBorderId()); ctXf.setXfId(cellXfs.getXfId()); ctXf.setParent(ctCellXfs); xfs.add(ctXf); } } }
public StyleSheet(CTStylesheet ctStylesheet) { this.ctStylesheet = ctStylesheet; CTCellStyles ctCellStyles = ctStylesheet.getCellStyles(); CTCellStyleXfs ctCellStyleXfs = ctStylesheet.getCellStyleXfs(); CTCellXfs ctCellXfs = ctStylesheet.getCellXfs(); if (ctCellStyles != null && ctCellStyleXfs != null) { for (CTCellStyle ctCellStyle : ctCellStyles.getCellStyle()) {
public void saveStyle() { if (!newCellXfs.isEmpty()) { CTCellXfs ctCellXfs = ctStylesheet.getCellXfs(); if (ctCellXfs == null) { ctCellXfs = new CTCellXfs(); ctStylesheet.setCellXfs(ctCellXfs); } ctCellXfs.setCount((long) cellXfsIndex.size()); List<CTXf> xfs = ctCellXfs.getXf(); for (CellXfs cellXfs : newCellXfs) { CTXf ctXf = new CTXf(); ctXf.setNumFmtId(cellXfs.getNumFmtId()); ctXf.setFontId(cellXfs.getFontId()); ctXf.setFillId(cellXfs.getFillId()); ctXf.setBorderId(cellXfs.getBorderId()); ctXf.setXfId(cellXfs.getXfId()); ctXf.setParent(ctCellXfs); xfs.add(ctXf); } } }
XSSFWorkbook wb = new XSSFWorkbook(...); StylesTable stylesTable = wb.getStylesSource(); CTStylesheet ct = stylesTable.getCTStylesheet(); CTCellStyles cellStyles = ct.getCellStyles(); // Prints the count from: <cellStyles count="3516"> System.out.println("Number of CT styles: " + cellStyles.getCount()); for (CTCellStyle style : cellStyles.getCellStyleList()) { // Prints the name // Example: <cellStyle name="Note 2" xfId="3506"/> // Prints: Note 2 System.out.println(style.getName()); }
/** * Cells in the Sheet Part reference the xf (data format) records by zero-based index. * * @param idx * @return */ public CTXf getXfByIndex(long idx) { if (this.getJaxbElement().getCellXfs()!=null) { return this.getJaxbElement().getCellXfs().getXf().get( (int)idx); } return null; }
/** * Create an instance of {@link CTStylesheet } * */ public CTStylesheet createCTStylesheet() { return new CTStylesheet(); }
/** * Get the cell style by index. * * @param idx * @return */ public CTCellStyle getStyleByIndex(long idx) { if (this.getJaxbElement().getCellStyles()!=null) { return this.getJaxbElement().getCellStyles().getCellStyle().get((int)idx); } return null; }