/** * Update sheet name in all formulas and named ranges. * Called from {@link XSSFWorkbook#SetSheetName(int, String)} * <p/> * <p> * The idea is to parse every formula and render it back to string * with the updated sheet name. The IFormulaParsingWorkbook passed to the formula Parser * is constructed from the old workbook (sheet name is not yet updated) and * the FormulaRenderingWorkbook passed to FormulaRenderer#toFormulaString is a custom implementation that * returns the new sheet name. * </p> * * @param sheetIndex the 0-based index of the sheet being Changed * @param name the new sheet name */ public void UpdateSheetName(int sheetIndex, String name) { /** * An instance of FormulaRenderingWorkbook that returns */ IFormulaRenderingWorkbook frwb = new XSSFFormulaRenderingWorkbook(_fpwb, sheetIndex, name); // update named ranges for (int i = 0; i < _wb.NumberOfNames; i++) { IName nm = _wb.GetNameAt(i); if (nm.SheetIndex == -1 || nm.SheetIndex == sheetIndex) { UpdateName(nm, frwb); } } // update formulas foreach (ISheet sh in _wb) { foreach (IRow row in sh) { foreach (ICell cell in row) { if (cell.CellType == CellType.Formula) { UpdateFormula((XSSFCell)cell, frwb); } } } } }
/** * Update sheet name in all formulas and named ranges. * Called from {@link XSSFWorkbook#SetSheetName(int, String)} * <p/> * <p> * The idea is to parse every formula and render it back to string * with the updated sheet name. The IFormulaParsingWorkbook passed to the formula Parser * is constructed from the old workbook (sheet name is not yet updated) and * the FormulaRenderingWorkbook passed to FormulaRenderer#toFormulaString is a custom implementation that * returns the new sheet name. * </p> * * @param sheetIndex the 0-based index of the sheet being Changed * @param name the new sheet name */ public void UpdateSheetName(int sheetIndex, String name) { /** * An instance of FormulaRenderingWorkbook that returns */ IFormulaRenderingWorkbook frwb = new XSSFFormulaRenderingWorkbook(_fpwb, sheetIndex, name); // update named ranges for (int i = 0; i < _wb.NumberOfNames; i++) { IName nm = _wb.GetNameAt(i); if (nm.SheetIndex == -1 || nm.SheetIndex == sheetIndex) { UpdateName(nm, frwb); } } // update formulas foreach (ISheet sh in _wb) { foreach (IRow row in sh) { foreach (ICell cell in row) { if (cell.CellType == CellType.FORMULA) { UpdateFormula((XSSFCell)cell, frwb); } } } } }