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
*/
public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
protected final XSSFWorkbook _uBook;
protected final XSSFWorkbook _uBook;
protected BaseXSSFEvaluationWorkbook(XSSFWorkbook book) {
_uBook = book;
}
protected BaseXSSFEvaluationWorkbook(XSSFWorkbook book) {
_uBook = book;
}
private int convertFromExternalSheetIndex(int externSheetIndex) {
return externSheetIndex;
}
/**
* XSSF doesn't use external sheet indexes, so when asked treat
* it just as a local index
*/
public int convertFromExternSheetIndex(int externSheetIndex) {
return externSheetIndex;
}
/**
* @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.
* Fairly easy on XSSF (we think...) since the internal and external
* indices are the same
*/
private int convertToExternalSheetIndex(int sheetIndex) {
return sheetIndex;
}
private int convertFromExternalSheetIndex(int externSheetIndex) {
return externSheetIndex;
}
/**
* XSSF doesn't use external sheet indexes, so when asked treat
* it just as a local index
*/
public int convertFromExternSheetIndex(int externSheetIndex) {
return externSheetIndex;
}
/**
* @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.
* Fairly easy on XSSF (we think...) since the internal and external
* indices are the same
*/
private int convertToExternalSheetIndex(int sheetIndex) {
return sheetIndex;
}
public int getExternalSheetIndex(String 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)
* @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);
String nameText = nm.getNameName();
int nameSheetindex = nm.getSheetIndex();
if (name.equalsIgnoreCase(nameText) &&
(nameSheetindex == -1 || nameSheetindex == sheetIndex)) {
return new Name(nm, i, this);
}
}
return sheetIndex == -1 ? null : getName(name, -1);
}
/**
* 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);
String nameText = nm.getNameName();
int nameSheetindex = nm.getSheetIndex();
if (name.equalsIgnoreCase(nameText) &&
(nameSheetindex == -1 || nameSheetindex == sheetIndex)) {
return new Name(nm, i, this);
}
}
return sheetIndex == -1 ? null : getName(name, -1);
}
public String getSheetName(int sheetIndex) {
return _uBook.getSheetName(sheetIndex);
}
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
public String getSheetName(int sheetIndex) {
return _uBook.getSheetName(sheetIndex);
}
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) {
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) {
// External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1;
@ -187,7 +187,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
int nameIdx = _uBook.getNameIndex(nameName);
return new ExternalName(nameName, nameIdx, 0); // TODO Is this right?
}
}
/**
@ -195,7 +195,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
*/
@Override
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();
FreeRefFunction func = udfFinder.findFunction(name);
if (func != null) {
@ -224,7 +224,7 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
} else {
return new NameXPxg(sheetName, name);
}
}
}
public Ptg get3DReferencePtg(CellReference cell, SheetIdentifier sheet) {
if (sheet._bookName != null) {
int bookIndex = resolveBookIndex(sheet._bookName);
@ -260,106 +260,106 @@ public abstract class BaseXSSFEvaluationWorkbook implements FormulaRenderingWork
return name;
}
public ExternalSheet getExternalSheet(int externSheetIndex) {
throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
}
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
String workbookName;
if (externalWorkbookNumber > 0) {
// External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1;
ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber);
workbookName = linkTable.getLinkedFileName();
} else {
// Internal reference
workbookName = null;
}
if (lastSheetName == null || firstSheetName.equals(lastSheetName)) {
return new ExternalSheet(workbookName, firstSheetName);
} else {
return new ExternalSheetRange(workbookName, firstSheetName, lastSheetName);
}
public ExternalSheet getExternalSheet(int externSheetIndex) {
throw new IllegalStateException("HSSF-style external references are not supported for XSSF");
}
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) {
String workbookName;
if (externalWorkbookNumber > 0) {
// External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1;
ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber);
workbookName = linkTable.getLinkedFileName();
} else {
// Internal reference
workbookName = null;
}
if (lastSheetName == null || firstSheetName.equals(lastSheetName)) {
return new ExternalSheet(workbookName, firstSheetName);
} else {
return new ExternalSheetRange(workbookName, firstSheetName, lastSheetName);
}
}
@NotImplemented
public int getExternalSheetIndex(String workbookName, String sheetName) {
throw new RuntimeException("not implemented yet");
}
public int getSheetIndex(String sheetName) {
return _uBook.getSheetIndex(sheetName);
}
throw new RuntimeException("not implemented yet");
}
public int getSheetIndex(String sheetName) {
return _uBook.getSheetIndex(sheetName);
}
public String getSheetFirstNameByExternSheet(int externSheetIndex) {
int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
return _uBook.getSheetName(sheetIndex);
}
public String getSheetFirstNameByExternSheet(int externSheetIndex) {
int sheetIndex = convertFromExternalSheetIndex(externSheetIndex);
return _uBook.getSheetName(sheetIndex);
}
public String getSheetLastNameByExternSheet(int externSheetIndex) {
// XSSF does multi-sheet references differently, so this is the same as the first
return getSheetFirstNameByExternSheet(externSheetIndex);
}
public String getNameText(NamePtg namePtg) {
return _uBook.getNameAt(namePtg.getIndex()).getNameName();
}
public EvaluationName getName(NamePtg namePtg) {
int ix = namePtg.getIndex();
return new Name(_uBook.getNameAt(ix), ix, this);
}
@Override
public XSSFName createName() {
return _uBook.createName();
}
public Table getTable(String name) {
return _uBook.getTable(name);
}
public String getNameText(NamePtg namePtg) {
return _uBook.getNameAt(namePtg.getIndex()).getNameName();
}
public EvaluationName getName(NamePtg namePtg) {
int ix = namePtg.getIndex();
return new Name(_uBook.getNameAt(ix), ix, this);
}
@Override
public XSSFName createName() {
return _uBook.createName();
}
public Table getTable(String name) {
return _uBook.getTable(name);
}
public UDFFinder getUDFFinder(){
return _uBook.getUDFFinder();
}
private static final class Name implements EvaluationName {
private static final class Name implements EvaluationName {
private final XSSFName _nameRecord;
private final int _index;
private final FormulaParsingWorkbook _fpBook;
private final XSSFName _nameRecord;
private final int _index;
private final FormulaParsingWorkbook _fpBook;
public Name(XSSFName name, int index, FormulaParsingWorkbook fpBook) {
_nameRecord = name;
_index = index;
_fpBook = fpBook;
}
public Name(XSSFName name, int index, FormulaParsingWorkbook fpBook) {
_nameRecord = name;
_index = index;
_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() {
return _nameRecord.getNameName();
}
public String getNameText() {
return _nameRecord.getNameName();
}
public boolean hasFormula() {
// TODO - no idea if this is right
CTDefinedName ctn = _nameRecord.getCTName();
String strVal = ctn.getStringValue();
return !ctn.getFunction() && strVal != null && strVal.length() > 0;
}
public boolean hasFormula() {
// TODO - no idea if this is right
CTDefinedName ctn = _nameRecord.getCTName();
String strVal = ctn.getStringValue();
return !ctn.getFunction() && strVal != null && strVal.length() > 0;
}
public boolean isFunctionName() {
return _nameRecord.isFunctionName();
}
public boolean isFunctionName() {
return _nameRecord.isFunctionName();
}
public boolean isRange() {
return hasFormula(); // TODO - is this right?
}
public NamePtg createPtg() {
return new NamePtg(_index);
}
}
public boolean isRange() {
return hasFormula(); // TODO - is this right?
}
public NamePtg createPtg() {
return new NamePtg(_index);
}
}
public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL2007;
}
public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL2007;
}
}

View File

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