/** * @param index * @return * @throws Xlsx4jException * @ since 3.0.1 */ public WorksheetPart getWorksheet(int index) throws Xlsx4jException { List<Sheet> sheets; try { sheets = this.getContents().getSheets().getSheet(); } catch (Docx4JException e1) { throw new Xlsx4jException(e1.getMessage(), e1); } int zeroBasedCount = sheets.size() -1; if (index< 0 || index>zeroBasedCount) { throw new Xlsx4jException("No sheet at index " + index + ". (There are " + sheets.size() + " sheets) "); } try { Sheet s = sheets.get(index); return (WorksheetPart)this.getRelationshipsPart().getPart(s.getId()); } catch (Exception e) { throw new Xlsx4jException("Sheet " + index + " not found", e); } }
Sheets sheets = wb.getJaxbElement().getSheets();
/** * @param index * @return * @throws Xlsx4jException * @ since 3.0.1 */ public WorksheetPart getWorksheet(int index) throws Xlsx4jException { List<Sheet> sheets; try { sheets = this.getContents().getSheets().getSheet(); } catch (Docx4JException e1) { throw new Xlsx4jException(e1.getMessage(), e1); } int zeroBasedCount = sheets.size() -1; if (index< 0 || index>zeroBasedCount) { throw new Xlsx4jException("No sheet at index " + index + ". (There are " + sheets.size() + " sheets) "); } try { Sheet s = sheets.get(index); return (WorksheetPart)this.getRelationshipsPart().getPart(s.getId()); } catch (Exception e) { throw new Xlsx4jException("Sheet " + index + " not found", e); } }
protected void updateSheetNames() { Sheets sheets = result.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (sheet.getName() != null) { sheet.setName(insertBandDataToString(sheet.getName())); } } } }
protected void updateSheetNames() { Sheets sheets = result.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (sheet.getName() != null) { sheet.setName(insertBandDataToString(sheet.getName())); } } } }
/** * 传入一个 xlsx 文件,和一个水印文件,给这个 xlsx 文件加水印 * @author eko.zhan at 2018年9月17日 下午2:10:50 * @throws Docx4JException * @throws Xlsx4jException */ @Override public void process() throws WatermarkException { try { SpreadsheetMLPackage excelMLPackage = SpreadsheetMLPackage.load(file); this.excelMLPackage = excelMLPackage; int size = excelMLPackage.getWorkbookPart().getContents().getSheets().getSheet().size(); for (int i=0;i<size;i++) { WorksheetPart worksheet = excelMLPackage.getWorkbookPart().getWorksheet(i); createBgPic(worksheet); } excelMLPackage.save(file); } catch (Docx4JException e) { throw new WatermarkException("Docx4JException", e); } catch (Xlsx4jException e) { throw new WatermarkException("Xlsx4jException", e); } }
if (relationship.getType().endsWith("worksheet")) { String sheetId = relationship.getId(); for (Sheet sheet : workbook.getSheets().getSheet()) { if (sheet.getId().equals(sheetId)) { worksheets.add(new SheetWrapper((WorksheetPart) part, sheet.getName()));
if (relationship.getType().endsWith("worksheet")) { String sheetId = relationship.getId(); for (Sheet sheet : workbook.getSheets().getSheet()) { if (sheet.getId().equals(sheetId)) { worksheets.add(new SheetWrapper((WorksheetPart) part, sheet.getName()));
protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, CTCalcChain calculationChain, int formulaCount) { CTCellFormula formula = cellWithFormula.getF(); formula.setValue(formula.getValue().replace(originalFormulaRange.toRange(), formulaRange.toRange())); if (originalFormulaRange.isOneCellRange() && formulaRange.isOneCellRange()) { //here we check that there are no alpha-numeric symbols around the single reference String pattern = "(?<!\\w+)" + originalFormulaRange.toFirstCellReference() + "(?!\\w+)"; formula.setValue(formula.getValue().replaceAll(pattern, formulaRange.toFirstCellReference())); } if (calculationChain != null) { CTCalcCell calcCell = new CTCalcCell(); calcCell.setR(cellWithFormula.getR()); String sheetName = originalFormulaRange.getSheet(); Sheets sheets = template.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (Objects.equals(sheet.getName(), sheetName)) { calcCell.setI((int) sheet.getSheetId()); break; } } } calculationChain.getC().add(calcCell); } }
protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, CTCalcChain calculationChain, int formulaCount) { CTCellFormula formula = cellWithFormula.getF(); formula.setValue(formula.getValue().replace(originalFormulaRange.toRange(), formulaRange.toRange())); if (originalFormulaRange.isOneCellRange() && formulaRange.isOneCellRange()) { //here we check that there are no alpha-numeric symbols around the single reference String pattern = "(?<!\\w+)" + originalFormulaRange.toFirstCellReference() + "(?!\\w+)"; formula.setValue(formula.getValue().replaceAll(pattern, formulaRange.toFirstCellReference())); } if (calculationChain != null) { CTCalcCell calcCell = new CTCalcCell(); calcCell.setR(cellWithFormula.getR()); String sheetName = originalFormulaRange.getSheet(); Sheets sheets = template.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (Objects.equals(sheet.getName(), sheetName)) { calcCell.setI((int) sheet.getSheetId()); break; } } } calculationChain.getC().add(calcCell); } }
Sheets sheets = wb.getJaxbElement().getSheets();