bug 61474, github #81: implement updateNamedRanges for ColumnShifter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
607ca594b1
commit
7c88f32408
@ -43,10 +43,9 @@ public final class XSSFColumnShifter extends ColumnShifter {
|
||||
/**
|
||||
* Updated named ranges
|
||||
*/
|
||||
@NotImplemented
|
||||
@Override
|
||||
public void updateNamedRanges(FormulaShifter formulaShifter) {
|
||||
throw new NotImplementedException("updateNamedRanges");
|
||||
XSSFRowColShifter.updateNamedRanges(sheet, formulaShifter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.apache.poi.xssf.usermodel.helpers;
|
||||
|
||||
import org.apache.poi.ss.formula.*;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.helpers.BaseRowColShifter;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
@ -37,6 +38,25 @@ import java.util.List;
|
||||
|
||||
private XSSFRowColShifter() { /*no instances for static classes*/}
|
||||
|
||||
/**
|
||||
* Updated named ranges
|
||||
*/
|
||||
/*package*/ static void updateNamedRanges(Sheet sheet, FormulaShifter formulaShifter) {
|
||||
Workbook wb = sheet.getWorkbook();
|
||||
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
|
||||
for (Name name : wb.getAllNames()) {
|
||||
String formula = name.getRefersToFormula();
|
||||
int sheetIndex = name.getSheetIndex();
|
||||
final int rowIndex = -1; //don't care, named ranges are not allowed to include structured references
|
||||
|
||||
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.NAMEDRANGE, sheetIndex, rowIndex);
|
||||
if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
|
||||
String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
|
||||
name.setRefersToFormula(shiftedFmla);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*package*/ static void updateHyperlinks(Sheet sheet, FormulaShifter formulaShifter) {
|
||||
int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
|
||||
List<? extends Hyperlink> hyperlinkList = sheet.getHyperlinkList();
|
||||
|
@ -65,19 +65,7 @@ public final class XSSFRowShifter extends RowShifter {
|
||||
*/
|
||||
@Override
|
||||
public void updateNamedRanges(FormulaShifter formulaShifter) {
|
||||
Workbook wb = sheet.getWorkbook();
|
||||
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
|
||||
for (Name name : wb.getAllNames()) {
|
||||
String formula = name.getRefersToFormula();
|
||||
int sheetIndex = name.getSheetIndex();
|
||||
final int rowIndex = -1; //don't care, named ranges are not allowed to include structured references
|
||||
|
||||
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.NAMEDRANGE, sheetIndex, rowIndex);
|
||||
if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
|
||||
String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
|
||||
name.setRefersToFormula(shiftedFmla);
|
||||
}
|
||||
}
|
||||
XSSFRowColShifter.updateNamedRanges(sheet, formulaShifter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user