whitespace (tabs to spaces)

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/xssf_structured_references@1747614 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-10 00:26:39 +00:00
parent 83abda843a
commit 588c19e9d3
2 changed files with 154 additions and 150 deletions

View File

@ -47,31 +47,31 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
* Internal POI use only - parent of XSSF and SXSSF evaluation workbooks * Internal POI use only - parent of XSSF and SXSSF evaluation workbooks
*/ */
public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook { public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
protected final XSSFWorkbook _uBook; protected final XSSFWorkbook _uBook;
protected BaseXSSFEvaluationWorkbook(XSSFWorkbook book) { protected BaseXSSFEvaluationWorkbook(XSSFWorkbook book) {
_uBook = book; _uBook = book;
} }
private int convertFromExternalSheetIndex(int externSheetIndex) { private int convertFromExternalSheetIndex(int externSheetIndex) {
return externSheetIndex; return externSheetIndex;
} }
/** /**
* XSSF doesn't use external sheet indexes, so when asked treat * XSSF doesn't use external sheet indexes, so when asked treat
* it just as a local index * it just as a local index
*/ */
public int convertFromExternSheetIndex(int externSheetIndex) { public int convertFromExternSheetIndex(int externSheetIndex) {
return externSheetIndex; return externSheetIndex;
} }
/** /**
* @return the external sheet index of the sheet with the given internal * @return the external sheet index of the sheet with the given internal
* index. Used by some of the more obscure formula and named range things. * index. Used by some of the more obscure formula and named range things.
* Fairly easy on XSSF (we think...) since the internal and external * Fairly easy on XSSF (we think...) since the internal and external
* indices are the same * indices are the same
*/ */
private int convertToExternalSheetIndex(int sheetIndex) { private int convertToExternalSheetIndex(int sheetIndex) {
return sheetIndex; return sheetIndex;
} }
public int getExternalSheetIndex(String sheetName) { public int getExternalSheetIndex(String sheetName) {
int sheetIndex = _uBook.getSheetIndex(sheetName); int sheetIndex = _uBook.getSheetIndex(sheetName);
@ -132,37 +132,37 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
} }
} }
/** /**
* Return EvaluationName wrapper around the matching XSSFName (named range) * Return EvaluationName wrapper around the matching XSSFName (named range)
* @param name case-aware but case-insensitive named range in workbook * @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 * @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. * if named range scope is global to the workbook, sheetIndex is -1.
* @return If name is a named range in the workbook, returns * @return If name is a named range in the workbook, returns
* EvaluationName corresponding to that named range * EvaluationName corresponding to that named range
* Returns null if there is no named range with the same name and scope in the workbook * Returns null if there is no named range with the same name and scope in the workbook
*/ */
public EvaluationName getName(String name, int sheetIndex) { public EvaluationName getName(String name, int sheetIndex) {
for (int i = 0; i < _uBook.getNumberOfNames(); i++) { for (int i = 0; i < _uBook.getNumberOfNames(); i++) {
XSSFName nm = _uBook.getNameAt(i); XSSFName nm = _uBook.getNameAt(i);
String nameText = nm.getNameName(); String nameText = nm.getNameName();
int nameSheetindex = nm.getSheetIndex(); int nameSheetindex = nm.getSheetIndex();
if (name.equalsIgnoreCase(nameText) && if (name.equalsIgnoreCase(nameText) &&
(nameSheetindex == -1 || nameSheetindex == sheetIndex)) { (nameSheetindex == -1 || nameSheetindex == sheetIndex)) {
return new Name(nm, i, this); return new Name(nm, i, this);
} }
} }
return sheetIndex == -1 ? null : getName(name, -1); return sheetIndex == -1 ? null : getName(name, -1);
} }
public String getSheetName(int sheetIndex) { public String getSheetName(int sheetIndex) {
return _uBook.getSheetName(sheetIndex); return _uBook.getSheetName(sheetIndex);
} }
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) { public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
throw new IllegalStateException("HSSF-style external references are not supported for XSSF"); throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
} }
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) { public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
if (externalWorkbookNumber > 0) { if (externalWorkbookNumber > 0) {
// External reference - reference is 1 based, link table is 0 based // External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1; int linkNumber = externalWorkbookNumber - 1;
@ -187,7 +187,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
int nameIdx = _uBook.getNameIndex(nameName); int nameIdx = _uBook.getNameIndex(nameName);
return new ExternalName(nameName, nameIdx, 0); // TODO Is this right? return new ExternalName(nameName, nameIdx, 0); // TODO Is this right?
} }
} }
/** /**
@ -195,7 +195,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
*/ */
@Override @Override
public NameXPxg getNameXPtg(String name, SheetIdentifier sheet) { public NameXPxg getNameXPtg(String name, SheetIdentifier sheet) {
// First, try to find it as a User Defined Function // First, try to find it as a User Defined Function
IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder(); IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
FreeRefFunction func = udfFinder.findFunction(name); FreeRefFunction func = udfFinder.findFunction(name);
if (func != null) { if (func != null) {
@ -224,7 +224,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
} else { } else {
return new NameXPxg(sheetName, name); return new NameXPxg(sheetName, name);
} }
} }
public Ptg get3DReferencePtg(CellReference cell, SheetIdentifier sheet) { public Ptg get3DReferencePtg(CellReference cell, SheetIdentifier sheet) {
if (sheet._bookName != null) { if (sheet._bookName != null) {
int bookIndex = resolveBookIndex(sheet._bookName); int bookIndex = resolveBookIndex(sheet._bookName);
@ -260,106 +260,106 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
return name; return name;
} }
public ExternalSheet getExternalSheet(int externSheetIndex) { public ExternalSheet getExternalSheet(int externSheetIndex) {
throw new IllegalStateException("HSSF-style external references are not supported for XSSF"); throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
} }
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) { public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
String workbookName; String workbookName;
if (externalWorkbookNumber > 0) { if (externalWorkbookNumber > 0) {
// External reference - reference is 1 based, link table is 0 based // External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1; int linkNumber = externalWorkbookNumber - 1;
ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber); ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber);
workbookName = linkTable.getLinkedFileName(); workbookName = linkTable.getLinkedFileName();
} else { } else {
// Internal reference // Internal reference
workbookName = null; workbookName = null;
} }
if (lastSheetName == null || firstSheetName.equals(lastSheetName)) { if (lastSheetName == null || firstSheetName.equals(lastSheetName)) {
return new ExternalSheet(workbookName, firstSheetName); return new ExternalSheet(workbookName, firstSheetName);
} else { } else {
return new ExternalSheetRange(workbookName, firstSheetName, lastSheetName); return new ExternalSheetRange(workbookName, firstSheetName, lastSheetName);
} }
} }
@NotImplemented @NotImplemented
public int getExternalSheetIndex(String workbookName, String sheetName) { public int getExternalSheetIndex(String workbookName, String sheetName) {
throw new RuntimeException("not implemented yet"); throw new RuntimeException("not implemented yet");
} }
public int getSheetIndex(String sheetName) { public int getSheetIndex(String sheetName) {
return _uBook.getSheetIndex(sheetName); return _uBook.getSheetIndex(sheetName);
} }
public String getSheetFirstNameByExternSheet(int externSheetIndex) { public String getSheetFirstNameByExternSheet(int externSheetIndex) {
int sheetIndex = convertFromExternalSheetIndex(externSheetIndex); int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
return _uBook.getSheetName(sheetIndex); return _uBook.getSheetName(sheetIndex);
} }
public String getSheetLastNameByExternSheet(int externSheetIndex) { public String getSheetLastNameByExternSheet(int externSheetIndex) {
// XSSF does multi-sheet references differently, so this is the same as the first // XSSF does multi-sheet references differently, so this is the same as the first
return getSheetFirstNameByExternSheet(externSheetIndex); return getSheetFirstNameByExternSheet(externSheetIndex);
} }
public String getNameText(NamePtg namePtg) { public String getNameText(NamePtg namePtg) {
return _uBook.getNameAt(namePtg.getIndex()).getNameName(); return _uBook.getNameAt(namePtg.getIndex()).getNameName();
} }
public EvaluationName getName(NamePtg namePtg) { public EvaluationName getName(NamePtg namePtg) {
int ix = namePtg.getIndex(); int ix = namePtg.getIndex();
return new Name(_uBook.getNameAt(ix), ix, this); return new Name(_uBook.getNameAt(ix), ix, this);
} }
@Override @Override
public XSSFName createName() { public XSSFName createName() {
return _uBook.createName(); return _uBook.createName();
} }
public Table getTable(String name) { public Table getTable(String name) {
return _uBook.getTable(name); return _uBook.getTable(name);
} }
public UDFFinder getUDFFinder(){ public UDFFinder getUDFFinder(){
return _uBook.getUDFFinder(); return _uBook.getUDFFinder();
} }
private static final class Name implements EvaluationName { private static final class Name implements EvaluationName {
private final XSSFName _nameRecord; private final XSSFName _nameRecord;
private final int _index; private final int _index;
private final FormulaParsingWorkbook _fpBook; private final FormulaParsingWorkbook _fpBook;
public Name(XSSFName name, int index, FormulaParsingWorkbook fpBook) { public Name(XSSFName name, int index, FormulaParsingWorkbook fpBook) {
_nameRecord = name; _nameRecord = name;
_index = index; _index = index;
_fpBook = fpBook; _fpBook = fpBook;
} }
public Ptg[] getNameDefinition() { public Ptg[] getNameDefinition() {
return FormulaParser.parse(_nameRecord.getRefersToFormula(), _fpBook, FormulaType.NAMEDRANGE, _nameRecord.getSheetIndex()); return FormulaParser.parse(_nameRecord.getRefersToFormula(), _fpBook, FormulaType.NAMEDRANGE, _nameRecord.getSheetIndex());
} }
public String getNameText() { public String getNameText() {
return _nameRecord.getNameName(); return _nameRecord.getNameName();
} }
public boolean hasFormula() { public boolean hasFormula() {
// TODO - no idea if this is right // TODO - no idea if this is right
CTDefinedName ctn = _nameRecord.getCTName(); CTDefinedName ctn = _nameRecord.getCTName();
String strVal = ctn.getStringValue(); String strVal = ctn.getStringValue();
return !ctn.getFunction() && strVal != null && strVal.length() > 0; return !ctn.getFunction() && strVal != null && strVal.length() > 0;
} }
public boolean isFunctionName() { public boolean isFunctionName() {
return _nameRecord.isFunctionName(); return _nameRecord.isFunctionName();
} }
public boolean isRange() { public boolean isRange() {
return hasFormula(); // TODO - is this right? return hasFormula(); // TODO - is this right?
} }
public NamePtg createPtg() { public NamePtg createPtg() {
return new NamePtg(_index); return new NamePtg(_index);
} }
} }
public SpreadsheetVersion getSpreadsheetVersion(){ public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL2007; return SpreadsheetVersion.EXCEL2007;
} }
} }

View File

@ -27,26 +27,30 @@ import org.apache.poi.ss.formula.ptg.Ptg;
* Internal POI use only * Internal POI use only
*/ */
public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook { public final class XSSFEvaluationWorkbook extends BaseXSSFEvaluationWorkbook {
public static XSSFEvaluationWorkbook create(XSSFWorkbook book) { @Override
if (book == null) { public static XSSFEvaluationWorkbook create(XSSFWorkbook book) {
return null; if (book == null) {
} return null;
return new XSSFEvaluationWorkbook(book); }
} return new XSSFEvaluationWorkbook(book);
}
private XSSFEvaluationWorkbook(XSSFWorkbook book) { private XSSFEvaluationWorkbook(XSSFWorkbook book) {
super(book); super(book);
} }
public int getSheetIndex(EvaluationSheet evalSheet) { @Override
XSSFSheet sheet = ((XSSFEvaluationSheet)evalSheet).getXSSFSheet(); public int getSheetIndex(EvaluationSheet evalSheet) {
return _uBook.getSheetIndex(sheet); XSSFSheet sheet = ((XSSFEvaluationSheet)evalSheet).getXSSFSheet();
} return _uBook.getSheetIndex(sheet);
}
public EvaluationSheet getSheet(int sheetIndex) { @Override
return new XSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex)); public EvaluationSheet getSheet(int sheetIndex) {
} return new XSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
}
@Override
public Ptg[] getFormulaTokens(EvaluationCell evalCell) { public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell(); XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook); XSSFEvaluationWorkbook frBook = XSSFEvaluationWorkbook.create(_uBook);