In the ooxml branch, convert the formula stuff from using hssf.HSSFWorkbook to ss.Workbook, so that everything now works for XSSF too

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@648454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-04-15 23:18:25 +00:00
parent 101e30ed37
commit d578c64812
60 changed files with 235 additions and 163 deletions

View File

@ -27,7 +27,7 @@ import java.util.regex.Pattern;
import org.apache.poi.hssf.record.formula.*;
import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* This class parses a formula string into a List of tokens in RPN order.
@ -87,7 +87,7 @@ public final class FormulaParser {
*/
private char look;
private HSSFWorkbook book;
private Workbook book;
/**
@ -102,14 +102,14 @@ public final class FormulaParser {
* model.Workbook, then use the convenience method on
* usermodel.HSSFFormulaEvaluator
*/
public FormulaParser(String formula, HSSFWorkbook book){
public FormulaParser(String formula, Workbook book){
formulaString = formula;
pointer=0;
this.book = book;
formulaLength = formulaString.length();
}
public static Ptg[] parse(String formula, HSSFWorkbook book) {
public static Ptg[] parse(String formula, Workbook book) {
FormulaParser fp = new FormulaParser(formula, book);
fp.parse();
return fp.getRPNPtg();
@ -252,7 +252,7 @@ public final class FormulaParser {
Match('!');
String sheetName = name;
String first = GetName();
short externIdx = book.getExternalSheetIndex(book.getSheetIndex(sheetName));
short externIdx = (short)book.getExternalSheetIndex(book.getSheetIndex(sheetName));
if (look == ':') {
Match(':');
String second=GetName();
@ -927,7 +927,7 @@ end;
* @param lptgs list of Ptg, can be null or empty
* @return a human readable String
*/
public static String toFormulaString(HSSFWorkbook book, List lptgs) {
public static String toFormulaString(Workbook book, List lptgs) {
String retval = null;
if (lptgs == null || lptgs.size() == 0) return "#NAME";
Ptg[] ptgs = new Ptg[lptgs.size()];
@ -953,7 +953,7 @@ end;
* @param ptgs array of Ptg, can be null or empty
* @return a human readable String
*/
public static String toFormulaString(HSSFWorkbook book, Ptg[] ptgs) {
public static String toFormulaString(Workbook book, Ptg[] ptgs) {
if (ptgs == null || ptgs.length == 0) {
// TODO - what is the justification for returning "#NAME" (which is not "#NAME?", btw)
return "#NAME";

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
@ -73,7 +73,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
return field_2_fnc_index == FUNCTION_INDEX_EXTERNAL;
}
public String toFormulaString(HSSFWorkbook book) {
public String toFormulaString(Workbook book) {
return getName();
}

View File

@ -23,7 +23,7 @@
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -75,7 +75,7 @@ public class AddPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "+";
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
@ -273,7 +273,7 @@ public class Area3DPtg extends Ptg implements AreaI
* @return text representation of this area reference that can be used in text
* formulas. The sheet name will get properly delimited if required.
*/
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
// First do the sheet name
StringBuffer retval = new StringBuffer();

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* Specifies a rectangular area of cells A1:A4 for instance.

View File

@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -66,7 +66,7 @@ public class AreaErrPtg extends AreaPtg
array[offset] = (byte) (sid + ptgClass);
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "#REF!";
}

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@ -58,7 +58,7 @@ public class AreaNAPtg
return "AreaNAPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@ -61,7 +61,7 @@ public class AreaNPtg
return "AreaNPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@ -59,7 +59,7 @@ public class AreaNVPtg
return "AreaNVPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -24,7 +24,7 @@ import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -303,11 +303,11 @@ public class AreaPtg
field_4_last_column = column;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return toFormulaString(this, book);
}
protected static String toFormulaString(AreaI area, HSSFWorkbook book) {
protected static String toFormulaString(AreaI area, Workbook book) {
CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative());

View File

@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* Specifies a rectangular area of cells A1:A4 for instance.

View File

@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord;
@ -198,7 +198,7 @@ public class ArrayPtg extends Ptg
return size;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
StringBuffer b = new StringBuffer();
b.append("{");

View File

@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord;

View File

@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord;

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndian;
@ -209,11 +209,11 @@ public final class AttrPtg extends OperationPtg {
if(space.isSet(field_1_options)) {
return operands[ 0 ];
} else if (optiIf.isSet(field_1_options)) {
return toFormulaString((HSSFWorkbook)null) + "(" + operands[ 0 ] +")";
return toFormulaString((Workbook)null) + "(" + operands[ 0 ] +")";
} else if (optGoto.isSet(field_1_options)) {
return toFormulaString((HSSFWorkbook)null) + operands[0]; //goto isn't a real formula element should not show up
return toFormulaString((Workbook)null) + operands[0]; //goto isn't a real formula element should not show up
} else {
return toFormulaString((HSSFWorkbook)null) + "(" + operands[ 0 ] + ")";
return toFormulaString((Workbook)null) + "(" + operands[ 0 ] + ")";
}
}
@ -228,7 +228,7 @@ public final class AttrPtg extends OperationPtg {
return -1;
}
public String toFormulaString(HSSFWorkbook book) {
public String toFormulaString(Workbook book) {
if(semiVolatile.isSet(field_1_options)) {
return "ATTR(semiVolatile)";
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -70,7 +70,7 @@ public class BoolPtg
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return field_1_value ? "TRUE" : "FALSE";
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -64,7 +64,7 @@ public class ConcatPtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return CONCAT;
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -65,7 +65,7 @@ public class DividePtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "/";
}
@ -74,7 +74,7 @@ public class DividePtg
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(toFormulaString((Workbook)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -64,7 +64,7 @@ public class EqualPtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "=";
}
@ -74,7 +74,7 @@ public class EqualPtg
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(toFormulaString((Workbook)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -19,7 +19,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
@ -70,7 +70,7 @@ public final class ErrPtg extends Ptg {
array[offset + 1] = (byte)field_1_error_code;
}
public String toFormulaString(HSSFWorkbook book) {
public String toFormulaString(Workbook book) {
return HSSFErrorConstants.getText(field_1_error_code);
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
@ -73,7 +73,7 @@ public class ExpPtg
return field_2_first_col;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RecordFormatException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
}

View File

@ -19,7 +19,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
@ -67,7 +67,7 @@ public class GreaterEqualPtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return ">=";
}
@ -77,7 +77,7 @@ public class GreaterEqualPtg
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(toFormulaString((Workbook)null));
buffer.append(operands[ 1 ]);
return buffer.toString();

View File

@ -25,7 +25,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -97,7 +97,7 @@ public class GreaterThanPtg
* Implementation of method from Ptg
* @param book the Sheet References
*/
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return this.GREATERTHAN;
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -72,7 +72,7 @@ public final class IntPtg extends Ptg {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book) {
public String toFormulaString(Workbook book) {
return String.valueOf(getValue());
}
public byte getDefaultOperandClass() {

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -59,7 +59,7 @@ public class IntersectionPtg extends OperationPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return " ";
}

View File

@ -20,7 +20,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
@ -68,7 +68,7 @@ public class LessEqualPtg
return 2;
}
public String toFormulaString( HSSFWorkbook book )
public String toFormulaString( Workbook book )
{
return "<=";
}
@ -77,7 +77,7 @@ public class LessEqualPtg
{
StringBuffer buffer = new StringBuffer();
buffer.append( operands[0] );
buffer.append( toFormulaString( (HSSFWorkbook) null ) );
buffer.append( toFormulaString( (Workbook) null ) );
buffer.append( operands[1] );
return buffer.toString();
}

View File

@ -27,7 +27,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
//POI
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -106,7 +106,7 @@ public class LessThanPtg
* Implementation of method from Ptg
* @param book the Sheet References
*/
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return this.LESSTHAN;
}

View File

@ -25,7 +25,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -83,7 +83,7 @@ public class MemAreaPtg
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return ""; // TODO: Not sure how to format this. -- DN
}

View File

@ -25,7 +25,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -57,7 +57,7 @@ public class MemErrPtg
array[offset] = (byte) (sid + ptgClass);
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "ERR#";
}

View File

@ -24,7 +24,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -60,7 +60,7 @@ public class MemFuncPtg extends ControlPtg
LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "";
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -55,7 +55,7 @@ public class MissingArgPtg
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return " ";
}

View File

@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -68,7 +68,7 @@ public class MultiplyPtg
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "*";
}
@ -77,9 +77,9 @@ public class MultiplyPtg
{
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ].toFormulaString((HSSFWorkbook)null));
buffer.append(operands[ 0 ].toFormulaString((Workbook)null));
buffer.append("*");
buffer.append(operands[ 1 ].toFormulaString((HSSFWorkbook)null));
buffer.append(operands[ 1 ].toFormulaString((Workbook)null));
return buffer.toString();
}
@ -87,7 +87,7 @@ public class MultiplyPtg
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(toFormulaString((Workbook)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -17,11 +17,10 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.LittleEndian;
/**
*
@ -49,13 +48,13 @@ public class NamePtg
* in the workbook. The search for the name record is case insensitive. If it is not found,
* it gets created.
*/
public NamePtg(String name, HSSFWorkbook book) {
public NamePtg(String name, Workbook book) {
field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based
}
/**
* @return zero based index of the found or newly created defined name record.
*/
private static final int getOrCreateNameRecord(HSSFWorkbook book, String name) {
private static final int getOrCreateNameRecord(Workbook book, String name) {
// perhaps this logic belongs in Workbook?
int countNames = book.getNumberOfNames();
for (int i = 0; i < countNames; i++) {
@ -64,7 +63,7 @@ public class NamePtg
}
}
HSSFName nameObj = book.createName();
Name nameObj = book.createName();
nameObj.setNameName(name);
return countNames;
@ -99,7 +98,7 @@ public class NamePtg
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return book.getNameName(field_1_label_index - 1);
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -61,7 +61,7 @@ public final class NameXPtg extends Ptg {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
// -1 to convert definedNameIndex from 1-based to zero-based
return book.resolveNameXText(field_1_ixals, field_2_ilbl-1);

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -64,7 +64,7 @@ public class NotEqualPtg
return 2;
}
public String toFormulaString( HSSFWorkbook book )
public String toFormulaString( Workbook book )
{
return "<>";
}
@ -75,7 +75,7 @@ public class NotEqualPtg
buffer.append( operands[0] );
buffer.append( toFormulaString( (HSSFWorkbook) null ) );
buffer.append( toFormulaString( (Workbook) null ) );
buffer.append( operands[1] );
return buffer.toString();

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -78,7 +78,7 @@ public class NumberPtg
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "" + getValue();
}

View File

@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -71,7 +71,7 @@ public class ParenthesisPtg
return 1;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "()";
}

View File

@ -23,7 +23,7 @@
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -74,7 +74,7 @@ public class PercentPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "%";
}

View File

@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -66,7 +66,7 @@ public class PowerPtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "^";
}
@ -76,7 +76,7 @@ public class PowerPtg
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(toFormulaString((Workbook)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Stack;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -418,7 +418,7 @@ public abstract class Ptg
/**
* return a string representation of this token alone
*/
public abstract String toFormulaString(HSSFWorkbook book);
public abstract String toFormulaString(Workbook book);
/**
* dump a debug representation (hexdump) to a string
*/

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -59,7 +59,7 @@ public class RangePtg extends OperationPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return ":";
}

View File

@ -18,11 +18,11 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.SheetReferences;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
@ -162,8 +162,8 @@ public class Ref3DPtg extends Ptg {
}
// TODO - find a home for this method
// There is already a method on HSSFWorkbook called getSheetName but it seems to do something different.
static String getSheetName(HSSFWorkbook book, int externSheetIndex) {
// There is already a method on Workbook called getSheetName but it seems to do something different.
static String getSheetName(Workbook book, int externSheetIndex) {
// TODO - there are 3 ways this method can return null. Is each valid?
if (book == null) {
return null;
@ -179,7 +179,7 @@ public class Ref3DPtg extends Ptg {
* @return text representation of this cell reference that can be used in text
* formulas. The sheet name will get properly delimited if required.
*/
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
StringBuffer retval = new StringBuffer();
String sheetName = getSheetName(book, field_1_index_extern_sheet);

View File

@ -21,7 +21,7 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -74,7 +74,7 @@ public class RefErrorPtg extends Ptg
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
return "#REF!";

View File

@ -28,7 +28,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* RefNAPtg
@ -57,7 +57,7 @@ public class RefNAPtg extends ReferencePtg
return "RefNAPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -27,7 +27,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* RefNPtg
@ -58,7 +58,7 @@ public class RefNPtg extends ReferencePtg
return "RefNPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -23,7 +23,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
/**
* RefNVPtg
@ -54,7 +54,7 @@ public class RefNVPtg extends ReferencePtg
return "RefNVPtg";
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}

View File

@ -22,7 +22,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -176,7 +176,7 @@ public class ReferencePtg extends Ptg {
return SIZE;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil;
@ -109,7 +109,7 @@ public class StringPtg
}
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "\""+getValue()+"\"";
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -63,7 +63,7 @@ public class SubtractPtg
return 2;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "-";
}

View File

@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -69,7 +69,7 @@ public class UnaryMinusPtg extends OperationPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "+";
}

View File

@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -69,7 +69,7 @@ public class UnaryPlusPtg extends OperationPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "+";
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -59,7 +59,7 @@ public class UnionPtg extends OperationPtg
}
/** Implementation of method from Ptg */
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return ",";
}

View File

@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@ -51,7 +51,7 @@ public class UnknownPtg
return size;
}
public String toFormulaString(HSSFWorkbook book)
public String toFormulaString(Workbook book)
{
return "UNKNOWN";
}

View File

@ -112,7 +112,8 @@ public class HSSFName implements Name {
private void setSheetName(String sheetName){
int sheetNumber = book.getSheetIndex(sheetName);
short externSheetNumber = book.getExternalSheetIndex(sheetNumber);
short externSheetNumber = (short)
book.getExternalSheetIndex(sheetNumber);
name.setExternSheetNumber(externSheetNumber);
// name.setIndexToSheet(externSheetNumber);

View File

@ -548,7 +548,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
* Used by some of the more obscure formula and
* named range things.
*/
public short getExternalSheetIndex(int internalSheetIndex) {
public int getExternalSheetIndex(int internalSheetIndex) {
return workbook.checkExternSheet(internalSheetIndex);
}

View File

@ -17,9 +17,6 @@
package org.apache.poi.hssf.util;
import java.util.HashMap;
import java.util.Map;
/**
* Holds a collection of Sheet names and their associated
* reference numbers.
@ -27,20 +24,6 @@ import java.util.Map;
* @author Andrew C. Oliver (acoliver at apache dot org)
*
*/
public class SheetReferences
public class SheetReferences extends org.apache.poi.ss.util.SheetReferences
{
Map map;
public SheetReferences()
{
map = new HashMap(5);
}
public void addSheetReference(String sheetName, int number) {
map.put(new Integer(number), sheetName);
}
public String getSheetName(int number) {
return (String)map.get(new Integer(number));
}
}

View File

@ -60,7 +60,6 @@ import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@ -333,16 +332,8 @@ public class FormulaEvaluator {
private static ValueEval evaluateCell(Workbook workbook, Sheet sheet,
int srcRowNum, short srcColNum, String cellFormulaText) {
FormulaParser parser;
if(workbook instanceof HSSFWorkbook) {
parser = HSSFFormulaEvaluator.getUnderlyingParser(
(HSSFWorkbook)workbook,
cellFormulaText
);
} else {
// Hope for the best...
parser = new FormulaParser(cellFormulaText, null);
}
FormulaParser parser =
new FormulaParser(cellFormulaText, workbook);
parser.parse();
Ptg[] ptgs = parser.getRPNPtg();

View File

@ -0,0 +1,46 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.util;
import java.util.HashMap;
import java.util.Map;
/**
* Holds a collection of Sheet names and their associated
* reference numbers.
*
* @author Andrew C. Oliver (acoliver at apache dot org)
*
*/
public class SheetReferences
{
Map map;
public SheetReferences()
{
map = new HashMap(5);
}
public void addSheetReference(String sheetName, int number) {
map.put(new Integer(number), sheetName);
}
public String getSheetName(int number) {
return (String)map.get(new Integer(number));
}
}

View File

@ -21,6 +21,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import org.apache.poi.ss.util.SheetReferences;
public interface Workbook {
/**
@ -141,6 +143,15 @@ public interface Workbook {
*/
int getSheetIndex(Sheet sheet);
/**
* Returns the external sheet index of the sheet
* with the given internal index, creating one
* if needed.
* Used by some of the more obscure formula and
* named range things.
*/
int getExternalSheetIndex(int internalSheetIndex);
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
@ -206,6 +217,8 @@ public interface Workbook {
void removeSheetAt(int index);
SheetReferences getSheetReferences();
/**
* determine whether the Excel GUI will backup the workbook when saving.
*
@ -352,6 +365,14 @@ public interface Workbook {
*/
String getNameName(int index);
/**
* TODO - make this less cryptic / move elsewhere
* @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
* @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
* @return the string representation of the defined or external name
*/
String resolveNameXText(int refIndex, int definedNameIndex);
/**
* Sets the printarea for the sheet provided
* <p>

View File

@ -39,6 +39,7 @@ import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.SheetReferences;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.model.CommentsTable;
@ -499,6 +500,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
return -1;
}
/**
* TODO - figure out what the hell this methods does in
* HSSF...
*/
public String resolveNameXText(int refIndex, int definedNameIndex) {
// TODO Replace with something proper
return null;
}
public short getNumCellStyles() {
// TODO Auto-generated method stub
return 0;
@ -574,10 +584,31 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
return this.sheets.indexOf(sheet);
}
/**
* Returns the external sheet index of the sheet
* with the given internal index, creating one
* if needed.
* Used by some of the more obscure formula and
* named range things.
* Fairly easy on XSSF (we think...) since the
* internal and external indicies are the same
*/
public int getExternalSheetIndex(int internalSheetIndex) {
return internalSheetIndex;
}
public String getSheetName(int sheet) {
return this.workbook.getSheets().getSheetArray(sheet).getName();
}
public SheetReferences getSheetReferences() {
SheetReferences sr = new SheetReferences();
for(int i=0; i<getNumberOfSheets(); i++) {
sr.addSheetReference(getSheetName(i), i);
}
return sr;
}
public void insertChartRecord() {
// TODO Auto-generated method stub