mirror of https://github.com/apache/poi.git
supporting changes for bug 58452: copy cell formulas containing unregistered function names
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14736096ec
commit
775838e5a8
|
@ -63,6 +63,11 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
|||
_iBook = book.getWorkbook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HSSFName createName() {
|
||||
return _uBook.createName();
|
||||
}
|
||||
|
||||
public int getExternalSheetIndex(String sheetName) {
|
||||
int sheetIndex = _uBook.getSheetIndex(sheetName);
|
||||
return _iBook.checkExternSheet(sheetIndex);
|
||||
|
@ -79,6 +84,10 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
|
|||
int extIx = getSheetExtIx(sheet);
|
||||
return new Area3DPtg(areaRef, extIx);
|
||||
}
|
||||
/**
|
||||
* Return an external name (named range, function, user-defined function) Ptg
|
||||
*/
|
||||
@Override
|
||||
public NameXPtg getNameXPtg(String name, SheetIdentifier sheet) {
|
||||
int sheetRefIndex = getSheetExtIx(sheet);
|
||||
return _iBook.getNameXPtg(name, sheetRefIndex, _uBook.getUDFFinder());
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.ss.formula;
|
|||
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.Name;
|
||||
import org.apache.poi.ss.util.AreaReference;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
|
||||
|
@ -35,6 +36,14 @@ public interface FormulaParsingWorkbook {
|
|||
*/
|
||||
EvaluationName getName(String name, int sheetIndex);
|
||||
|
||||
/**
|
||||
* Return the underlying workbook
|
||||
*/
|
||||
Name createName();
|
||||
|
||||
/**
|
||||
* Return an external name (named range, function, user-defined function) Ptg
|
||||
*/
|
||||
Ptg getNameXPtg(String name, SheetIdentifier sheet);
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,6 +40,9 @@ public final class NameXPxg extends OperandPtg implements Pxg {
|
|||
public NameXPxg(String sheetName, String nameName) {
|
||||
this(-1, sheetName, nameName);
|
||||
}
|
||||
public NameXPxg(String nameName) {
|
||||
this(-1, null, nameName);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
|
|
@ -130,6 +130,15 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return EvaluationName wrapper around the matching XSSFName (named range)
|
||||
* @param name case-aware but case-insensitive named range in workbook
|
||||
* @param sheetIndex index of sheet if named range scope is limited to one sheet
|
||||
* if named range scope is global to the workbook, sheetIndex is -1.
|
||||
* @return If name is a named range in the workbook, returns
|
||||
* EvaluationName corresponding to that named range
|
||||
* Returns null if there is no named range with the same name and scope in the workbook
|
||||
*/
|
||||
public EvaluationName getName(String name, int sheetIndex) {
|
||||
for (int i = 0; i < _uBook.getNumberOfNames(); i++) {
|
||||
XSSFName nm = _uBook.getNameAt(i);
|
||||
|
@ -137,7 +146,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
|||
int nameSheetindex = nm.getSheetIndex();
|
||||
if (name.equalsIgnoreCase(nameText) &&
|
||||
(nameSheetindex == -1 || nameSheetindex == sheetIndex)) {
|
||||
return new Name(_uBook.getNameAt(i), i, this);
|
||||
return new Name(nm, i, this);
|
||||
}
|
||||
}
|
||||
return sheetIndex == -1 ? null : getName(name, -1);
|
||||
|
@ -179,6 +188,10 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an external name (named range, function, user-defined function) Pxg
|
||||
*/
|
||||
@Override
|
||||
public NameXPxg getNameXPtg(String name, SheetIdentifier sheet) {
|
||||
// First, try to find it as a User Defined Function
|
||||
IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
|
||||
|
@ -290,6 +303,10 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
|
|||
int ix = namePtg.getIndex();
|
||||
return new Name(_uBook.getNameAt(ix), ix, this);
|
||||
}
|
||||
@Override
|
||||
public XSSFName createName() {
|
||||
return _uBook.createName();
|
||||
}
|
||||
|
||||
public UDFFinder getUDFFinder(){
|
||||
return _uBook.getUDFFinder();
|
||||
|
|
|
@ -44,6 +44,9 @@ public class XSSFTestDataSamples {
|
|||
*/
|
||||
public static final String TEST_OUTPUT_DIR = "poi.test.xssf.output.dir";
|
||||
|
||||
public static File getSampleFile(String sampleFileName) {
|
||||
return HSSFTestDataSamples.getSampleFile(sampleFileName);
|
||||
}
|
||||
public static OPCPackage openSamplePackage(String sampleName) {
|
||||
try {
|
||||
return OPCPackage.open(
|
||||
|
|
Loading…
Reference in New Issue