/** * @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); } }
s.setName(sheetName); s.setId(r.getId()); s.setSheetId(sheetId);
/** * Create an instance of {@link Sheet } * */ public Sheet createSheet() { return new Sheet(); }
String sheetName = sheetInfo.getName(); theSheet = smartsheet.sheetResources().getSheet(sheetInfo.getId(), null, null, null, null, null, null, null); } catch (SmartsheetException ex) { Logger.getLogger(SampleCode.class.getName()).log(Level.SEVERE, null, ex); System.out.println("\nSheet: " + theSheet.getName() + "\n"); List<Column> columnList = theSheet.getColumns(); String columnHeader = null; for (Column col : columnList) { List<Row> rowList = theSheet.getRows(); for (Row row : rowList) { List<Cell> cellList = row.getCells();
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); } }
s.setName(sheetName); s.setId(r.getId()); s.setSheetId(sheetId);
/** * @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); } }
/** * Create an instance of {@link Sheet } * */ public Sheet createSheet() { return new Sheet(); }