Nice and small change here... Update the formula parser code to use usermodel.HSSFWorkbook instead of model.Workbook. This should keep things a bit cleaner, and make it much easier for the formula code to work with XSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@648303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-04-15 16:00:50 +00:00
parent 437dc3b77d
commit a51afa06f4
75 changed files with 254 additions and 227 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! --> <!-- Don't forget to update status.xml too! -->
<release version="3.0.3-beta1" date="2008-04-??"> <release version="3.0.3-beta1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="fix">Update the formula parser code to use a HSSFWorkbook, rather than the low level model.Workbook, to make things cleaner and make supporting XSSF formulas in future much easier</action>
<action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action> <action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action>
<action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action> <action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action>
<action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action> <action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! --> <!-- Don't forget to update changes.xml too! -->
<changes> <changes>
<release version="3.0.3-beta1" date="2008-04-??"> <release version="3.0.3-beta1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="fix">Update the formula parser code to use a HSSFWorkbook, rather than the low level model.Workbook, to make things cleaner and make supporting XSSF formulas in future much easier</action>
<action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action> <action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action>
<action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action> <action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action>
<action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action> <action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action>

View File

@ -32,6 +32,7 @@ import java.util.List;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.formula.*; import org.apache.poi.hssf.record.formula.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.model.*; import org.apache.poi.hssf.model.*;
/** /**
@ -99,7 +100,7 @@ public class FormulaViewer
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
if (token instanceof ExpPtg) return; if (token instanceof ExpPtg) return;
buf.append(name=((OperationPtg) token).toFormulaString((Workbook)null)); buf.append(name=((OperationPtg) token).toFormulaString((HSSFWorkbook)null));
buf.append(sep); buf.append(sep);
switch (token.getPtgClass()) { switch (token.getPtgClass()) {
case Ptg.CLASS_REF : case Ptg.CLASS_REF :
@ -168,7 +169,7 @@ public class FormulaViewer
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
for (int i=0;i<numptgs;i++) { for (int i=0;i<numptgs;i++) {
token = (Ptg) tokens.get(i); token = (Ptg) tokens.get(i);
buf.append( token.toFormulaString((Workbook)null)); buf.append( token.toFormulaString((HSSFWorkbook)null));
switch (token.getPtgClass()) { switch (token.getPtgClass()) {
case Ptg.CLASS_REF : case Ptg.CLASS_REF :
buf.append("(R)"); buf.append("(R)");
@ -188,7 +189,7 @@ public class FormulaViewer
private String composeFormula(FormulaRecord record) private String composeFormula(FormulaRecord record)
{ {
return org.apache.poi.hssf.model.FormulaParser.toFormulaString((Workbook)null,record.getParsedExpression()); return org.apache.poi.hssf.model.FormulaParser.toFormulaString((HSSFWorkbook)null,record.getParsedExpression());
} }
/** /**

View File

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

View File

@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting; import org.apache.poi.hssf.record.cf.FontFormatting;
import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.hssf.record.cf.PatternFormatting;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -152,7 +153,7 @@ public final class CFRuleRecord extends Record
/** /**
* Creates a new comparison operation rule * Creates a new comparison operation rule
*/ */
public static CFRuleRecord create(Workbook workbook, String formulaText) { public static CFRuleRecord create(HSSFWorkbook workbook, String formulaText) {
Ptg[] formula1 = parseFormula(formulaText, workbook); Ptg[] formula1 = parseFormula(formulaText, workbook);
return new CFRuleRecord(CONDITION_TYPE_FORMULA, ComparisonOperator.NO_COMPARISON, return new CFRuleRecord(CONDITION_TYPE_FORMULA, ComparisonOperator.NO_COMPARISON,
formula1, null); formula1, null);
@ -160,7 +161,7 @@ public final class CFRuleRecord extends Record
/** /**
* Creates a new comparison operation rule * Creates a new comparison operation rule
*/ */
public static CFRuleRecord create(Workbook workbook, byte comparisonOperation, public static CFRuleRecord create(HSSFWorkbook workbook, byte comparisonOperation,
String formulaText1, String formulaText2) { String formulaText1, String formulaText2) {
Ptg[] formula1 = parseFormula(formulaText1, workbook); Ptg[] formula1 = parseFormula(formulaText1, workbook);
Ptg[] formula2 = parseFormula(formulaText2, workbook); Ptg[] formula2 = parseFormula(formulaText2, workbook);
@ -651,7 +652,7 @@ public final class CFRuleRecord extends Record
/** /**
* @return <code>null</code> if <tt>formula</tt> was null. * @return <code>null</code> if <tt>formula</tt> was null.
*/ */
private static Ptg[] parseFormula(String formula, Workbook workbook) private static Ptg[] parseFormula(String formula, HSSFWorkbook workbook)
{ {
if(formula == null) { if(formula == null) {
return null; return null;

View File

@ -18,12 +18,17 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import java.util.Iterator;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.*; import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.Ref3DPtg;
import org.apache.poi.hssf.record.formula.UnionPtg;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.RangeAddress; import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
@ -645,7 +650,7 @@ public class NameRecord extends Record {
/** gets the reference , the area only (range) /** gets the reference , the area only (range)
* @return area reference * @return area reference
*/ */
public String getAreaReference(Workbook book){ public String getAreaReference(HSSFWorkbook book){
if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "Error"; if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "Error";
Ptg ptg = (Ptg) field_13_name_definition.peek(); Ptg ptg = (Ptg) field_13_name_definition.peek();
String result = ""; String result = "";
@ -679,7 +684,7 @@ public class NameRecord extends Record {
* return an empty string if nothing is possible * return an empty string if nothing is possible
* for it. * for it.
*/ */
private String getAreaRefString(Ptg ptg,Workbook book) { private String getAreaRefString(Ptg ptg,HSSFWorkbook book) {
if (ptg.getClass() == Area3DPtg.class){ if (ptg.getClass() == Area3DPtg.class){
return ptg.toFormulaString(book); return ptg.toFormulaString(book);
} else if (ptg.getClass() == Ref3DPtg.class){ } else if (ptg.getClass() == Ref3DPtg.class){

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.formula.function.FunctionMetadata; import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry; 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; return field_2_fnc_index == FUNCTION_INDEX_EXTERNAL;
} }
public String toFormulaString(Workbook book) { public String toFormulaString(HSSFWorkbook book) {
return getName(); return getName();
} }

View File

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

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; 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 * @return text representation of this area reference that can be used in text
* formulas. The sheet name will get properly delimited if required. * formulas. The sheet name will get properly delimited if required.
*/ */
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
// First do the sheet name // First do the sheet name
StringBuffer retval = new StringBuffer(); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Specifies a rectangular area of cells A1:A4 for instance. * 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.LittleEndian;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
/** /**
@ -66,7 +66,7 @@ public class AreaErrPtg extends AreaPtg
array[offset] = (byte) (sid + ptgClass); array[offset] = (byte) (sid + ptgClass);
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
return "#REF!"; 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.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Specifies a rectangular area of cells A1:A4 for instance. * Specifies a rectangular area of cells A1:A4 for instance.
@ -58,7 +58,7 @@ public class AreaNAPtg
return "AreaNAPtg"; return "AreaNAPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Specifies a rectangular area of cells A1:A4 for instance. * Specifies a rectangular area of cells A1:A4 for instance.
@ -61,7 +61,7 @@ public class AreaNPtg
return "AreaNPtg"; return "AreaNPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Specifies a rectangular area of cells A1:A4 for instance. * Specifies a rectangular area of cells A1:A4 for instance.
@ -59,7 +59,7 @@ public class AreaNVPtg
return "AreaNVPtg"; return "AreaNVPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
/** /**
@ -303,11 +303,11 @@ public class AreaPtg
field_4_last_column = column; field_4_last_column = column;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
return toFormulaString(this, book); return toFormulaString(this, book);
} }
protected static String toFormulaString(AreaI area, Workbook book) { protected static String toFormulaString(AreaI area, HSSFWorkbook book) {
CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative()); CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative()); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference; import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Specifies a rectangular area of cells A1:A4 for instance. * 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.util.StringUtil;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord; import org.apache.poi.hssf.record.SSTRecord;
@ -198,7 +198,7 @@ public class ArrayPtg extends Ptg
return size; return size;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
StringBuffer b = new StringBuffer(); StringBuffer b = new StringBuffer();
b.append("{"); b.append("{");

View File

@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord; 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.util.StringUtil;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord; import org.apache.poi.hssf.record.SSTRecord;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants; 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; array[offset + 1] = (byte)field_1_error_code;
} }
public String toFormulaString(Workbook book) { public String toFormulaString(HSSFWorkbook book) {
return HSSFErrorConstants.getText(field_1_error_code); return HSSFErrorConstants.getText(field_1_error_code);
} }

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
@ -73,7 +73,7 @@ public class ExpPtg
return field_2_first_col; return field_2_first_col;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RecordFormatException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't"); 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; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
@ -67,7 +67,7 @@ public class GreaterEqualPtg
return 2; return 2;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
return ">="; return ">=";
} }
@ -77,7 +77,7 @@ public class GreaterEqualPtg
buffer.append(operands[ 0 ]); buffer.append(operands[ 0 ]);
buffer.append(toFormulaString((Workbook)null)); buffer.append(toFormulaString((HSSFWorkbook)null));
buffer.append(operands[ 1 ]); buffer.append(operands[ 1 ]);
return buffer.toString(); return buffer.toString();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; 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 ); LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
return ""; return "";
} }

View File

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

View File

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

View File

@ -18,7 +18,8 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.model.Workbook; 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.NameRecord;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
@ -48,26 +49,24 @@ public class NamePtg
* in the workbook. The search for the name record is case insensitive. If it is not found, * in the workbook. The search for the name record is case insensitive. If it is not found,
* it gets created. * it gets created.
*/ */
public NamePtg(String name, Workbook book) { public NamePtg(String name, HSSFWorkbook book) {
field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based 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. * @return zero based index of the found or newly created defined name record.
*/ */
private static final int getOrCreateNameRecord(Workbook book, String name) { private static final int getOrCreateNameRecord(HSSFWorkbook book, String name) {
// perhaps this logic belongs in Workbook // perhaps this logic belongs in Workbook?
int countNames = book.getNumNames(); int countNames = book.getNumberOfNames();
NameRecord rec;
for (int i = 0; i < countNames; i++) { for (int i = 0; i < countNames; i++) {
rec = book.getNameRecord(i); if(name.equalsIgnoreCase( book.getNameName(i) )) {
if (name.equalsIgnoreCase(rec.getNameText())) {
return i; return i;
} }
} }
rec = new NameRecord();
rec.setNameText(name); HSSFName nameObj = book.createName();
rec.setNameTextLength((byte) name.length()); nameObj.setNameName(name);
book.addName(rec);
return countNames; return countNames;
} }
@ -100,10 +99,9 @@ public class NamePtg
return SIZE; return SIZE;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
NameRecord rec = book.getNameRecord(field_1_label_index - 1); return book.getNameName(field_1_label_index - 1);
return rec.getNameText();
} }
public byte getDefaultOperandClass() {return Ptg.CLASS_REF;} public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.RangeAddress; import org.apache.poi.hssf.util.RangeAddress;
@ -162,8 +162,8 @@ public class Ref3DPtg extends Ptg {
} }
// TODO - find a home for this method // TODO - find a home for this method
// There is already a method on Workbook called getSheetName but it seems to do something different. // There is already a method on HSSFWorkbook called getSheetName but it seems to do something different.
static String getSheetName(Workbook book, int externSheetIndex) { static String getSheetName(HSSFWorkbook book, int externSheetIndex) {
// TODO - there are 3 ways this method can return null. Is each valid? // TODO - there are 3 ways this method can return null. Is each valid?
if (book == null) { if (book == null) {
return 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 * @return text representation of this cell reference that can be used in text
* formulas. The sheet name will get properly delimited if required. * formulas. The sheet name will get properly delimited if required.
*/ */
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
StringBuffer retval = new StringBuffer(); StringBuffer retval = new StringBuffer();
String sheetName = getSheetName(book, field_1_index_extern_sheet); 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.util.BitField;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
/** /**
@ -74,7 +74,7 @@ public class RefErrorPtg extends Ptg
return SIZE; return SIZE;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe! //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
return "#REF!"; 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.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* RefNAPtg * RefNAPtg
@ -57,7 +57,7 @@ public class RefNAPtg extends ReferencePtg
return "RefNAPtg"; return "RefNAPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* RefNPtg * RefNPtg
@ -58,7 +58,7 @@ public class RefNPtg extends ReferencePtg
return "RefNPtg"; return "RefNPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* RefNVPtg * RefNVPtg
@ -54,7 +54,7 @@ public class RefNVPtg extends ReferencePtg
return "RefNVPtg"; return "RefNVPtg";
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); 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.util.BitFieldFactory;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
/** /**
@ -176,7 +176,7 @@ public class ReferencePtg extends Ptg {
return SIZE; return SIZE;
} }
public String toFormulaString(Workbook book) public String toFormulaString(HSSFWorkbook book)
{ {
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe! //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(); return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -113,7 +113,7 @@ public class HSSFCell
private int cellType; private int cellType;
private HSSFRichTextString stringValue; private HSSFRichTextString stringValue;
private short encoding = ENCODING_UNCHANGED; private short encoding = ENCODING_UNCHANGED;
private Workbook book; private HSSFWorkbook book;
private Sheet sheet; private Sheet sheet;
private CellValueRecordInterface record; private CellValueRecordInterface record;
private HSSFComment comment; private HSSFComment comment;
@ -136,7 +136,7 @@ public class HSSFCell
*/ */
//protected HSSFCell(Workbook book, Sheet sheet, short row, short col) //protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
protected HSSFCell(Workbook book, Sheet sheet, int row, short col) protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col)
{ {
checkBounds(col); checkBounds(col);
stringValue = null; stringValue = null;
@ -165,7 +165,7 @@ public class HSSFCell
*/ */
//protected HSSFCell(Workbook book, Sheet sheet, short row, short col, //protected HSSFCell(Workbook book, Sheet sheet, short row, short col,
protected HSSFCell(Workbook book, Sheet sheet, int row, short col, protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col,
int type) int type)
{ {
checkBounds(col); checkBounds(col);
@ -188,7 +188,7 @@ public class HSSFCell
*/ */
//protected HSSFCell(Workbook book, Sheet sheet, short row, //protected HSSFCell(Workbook book, Sheet sheet, short row,
protected HSSFCell(Workbook book, Sheet sheet, int row, protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row,
CellValueRecordInterface cval) CellValueRecordInterface cval)
{ {
record = cval; record = cval;
@ -199,7 +199,7 @@ public class HSSFCell
switch (cellType) switch (cellType)
{ {
case CELL_TYPE_STRING : case CELL_TYPE_STRING :
stringValue = new HSSFRichTextString(book, (LabelSSTRecord ) cval); stringValue = new HSSFRichTextString(book.getWorkbook(), (LabelSSTRecord ) cval);
break; break;
case CELL_TYPE_BLANK : case CELL_TYPE_BLANK :
@ -209,7 +209,7 @@ public class HSSFCell
stringValue=new HSSFRichTextString(((FormulaRecordAggregate) cval).getStringValue()); stringValue=new HSSFRichTextString(((FormulaRecordAggregate) cval).getStringValue());
break; break;
} }
ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex()); ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(cval.getXFIndex());
setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf, book)); setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf, book));
} }
@ -265,7 +265,7 @@ public class HSSFCell
* @return * @return
*/ */
protected Workbook getBoundWorkbook() { protected Workbook getBoundWorkbook() {
return book; return book.getWorkbook();
} }
/** /**
@ -411,9 +411,9 @@ public class HSSFCell
// jmh { // jmh {
// jmh str.setUncompressedUnicode(); // jmh str.setUncompressedUnicode();
// jmh } // jmh }
sst = book.addSSTString(str); sst = book.getWorkbook().addSSTString(str);
lrec.setSSTIndex(sst); lrec.setSSTIndex(sst);
getRichStringCellValue().setUnicodeString(book.getSSTString(sst)); getRichStringCellValue().setUnicodeString(book.getWorkbook().getSSTString(sst));
} }
} }
record = lrec; record = lrec;
@ -540,7 +540,7 @@ public class HSSFCell
*/ */
public void setCellValue(Date value) public void setCellValue(Date value)
{ {
setCellValue(HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing())); setCellValue(HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()));
} }
/** /**
@ -560,7 +560,7 @@ public class HSSFCell
*/ */
public void setCellValue(Calendar value) public void setCellValue(Calendar value)
{ {
setCellValue( HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing()) ); setCellValue( HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()) );
} }
/** /**
@ -614,11 +614,11 @@ public class HSSFCell
int index = 0; int index = 0;
UnicodeString str = value.getUnicodeString(); UnicodeString str = value.getUnicodeString();
index = book.addSSTString(str); index = book.getWorkbook().addSSTString(str);
(( LabelSSTRecord ) record).setSSTIndex(index); (( LabelSSTRecord ) record).setSSTIndex(index);
stringValue = value; stringValue = value;
stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record)); stringValue.setWorkbookReferences(book.getWorkbook(), (( LabelSSTRecord ) record));
stringValue.setUnicodeString(book.getSSTString(index)); stringValue.setUnicodeString(book.getWorkbook().getSSTString(index));
} }
public void setCellFormula(String formula) { public void setCellFormula(String formula) {
@ -728,7 +728,7 @@ public class HSSFCell
"You cannot get a date value from an error cell"); "You cannot get a date value from an error cell");
} }
double value=this.getNumericCellValue(); double value=this.getNumericCellValue();
if (book.isUsing1904DateWindowing()) { if (book.getWorkbook().isUsing1904DateWindowing()) {
return HSSFDateUtil.getJavaDate(value,true); return HSSFDateUtil.getJavaDate(value,true);
} }
else { else {
@ -913,7 +913,7 @@ public class HSSFCell
public HSSFCellStyle getCellStyle() public HSSFCellStyle getCellStyle()
{ {
short styleIndex=record.getXFIndex(); short styleIndex=record.getXFIndex();
ExtendedFormatRecord xf = book.getExFormatAt(styleIndex); ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
return new HSSFCellStyle(styleIndex, xf, book); return new HSSFCellStyle(styleIndex, xf, book);
} }

View File

@ -84,7 +84,7 @@ import org.apache.poi.hssf.util.Region;
*/ */
public final class HSSFConditionalFormatting public final class HSSFConditionalFormatting
{ {
private final Workbook workbook; private final HSSFWorkbook workbook;
private final CFRecordsAggregate cfAggregate; private final CFRecordsAggregate cfAggregate;
HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
@ -95,7 +95,7 @@ public final class HSSFConditionalFormatting
if(cfAggregate == null) { if(cfAggregate == null) {
throw new IllegalArgumentException("cfAggregate must not be null"); throw new IllegalArgumentException("cfAggregate must not be null");
} }
workbook = sheet.workbook.getWorkbook(); workbook = sheet.workbook;
this.cfAggregate = cfAggregate; this.cfAggregate = cfAggregate;
} }
CFRecordsAggregate getCFRecordsAggregate() { CFRecordsAggregate getCFRecordsAggregate() {

View File

@ -40,13 +40,13 @@ public final class HSSFConditionalFormattingRule
private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS; private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
private final CFRuleRecord cfRuleRecord; private final CFRuleRecord cfRuleRecord;
private final Workbook workbook; private final HSSFWorkbook workbook;
HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord) { HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord) {
workbook = pWorkbook; workbook = pWorkbook;
cfRuleRecord = pRuleRecord; cfRuleRecord = pRuleRecord;
} }
HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord, HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord,
HSSFFontFormatting fontFmt, HSSFBorderFormatting bordFmt, HSSFPatternFormatting patternFmt) { HSSFFontFormatting fontFmt, HSSFBorderFormatting bordFmt, HSSFPatternFormatting patternFmt) {
this(pWorkbook, pRuleRecord); this(pWorkbook, pRuleRecord);
setFontFormatting(fontFmt); setFontFormatting(fontFmt);

View File

@ -115,7 +115,7 @@ public class HSSFFormulaEvaluator {
* formula evaluated. * formula evaluated.
*/ */
public static FormulaParser getUnderlyingParser(HSSFWorkbook workbook, String formula) { public static FormulaParser getUnderlyingParser(HSSFWorkbook workbook, String formula) {
return new FormulaParser(formula, workbook.getWorkbook()); return new FormulaParser(formula, workbook);
} }
/** /**
@ -343,7 +343,7 @@ public class HSSFFormulaEvaluator {
} }
private static ValueEval evaluateCell(HSSFWorkbook workbook, HSSFSheet sheet, private static ValueEval evaluateCell(HSSFWorkbook workbook, HSSFSheet sheet,
int srcRowNum, short srcColNum, String cellFormulaText) { int srcRowNum, short srcColNum, String cellFormulaText) {
FormulaParser parser = new FormulaParser(cellFormulaText, workbook.getWorkbook()); FormulaParser parser = new FormulaParser(cellFormulaText, workbook);
parser.parse(); parser.parse();
Ptg[] ptgs = parser.getRPNPtg(); Ptg[] ptgs = parser.getRPNPtg();
// -- parsing over -- // -- parsing over --
@ -760,7 +760,7 @@ public class HSSFFormulaEvaluator {
* @param workbook * @param workbook
*/ */
void inspectPtgs(String formula) { void inspectPtgs(String formula) {
FormulaParser fp = new FormulaParser(formula, workbook.getWorkbook()); FormulaParser fp = new FormulaParser(formula, workbook);
fp.parse(); fp.parse();
Ptg[] ptgs = fp.getRPNPtg(); Ptg[] ptgs = fp.getRPNPtg();
System.out.println("<ptg-group>"); System.out.println("<ptg-group>");

View File

@ -29,7 +29,7 @@ import org.apache.poi.hssf.util.RangeAddress;
*/ */
public class HSSFName { public class HSSFName {
private Workbook book; private HSSFWorkbook book;
private NameRecord name; private NameRecord name;
/** Creates new HSSFName - called by HSSFWorkbook to create a sheet from /** Creates new HSSFName - called by HSSFWorkbook to create a sheet from
@ -40,7 +40,7 @@ public class HSSFName {
* @param book lowlevel Workbook object associated with the sheet. * @param book lowlevel Workbook object associated with the sheet.
*/ */
protected HSSFName(Workbook book, NameRecord name) { protected HSSFName(HSSFWorkbook book, NameRecord name) {
this.book = book; this.book = book;
this.name = name; this.name = name;
} }
@ -53,7 +53,7 @@ public class HSSFName {
String result ; String result ;
short indexToExternSheet = name.getExternSheetNumber(); short indexToExternSheet = name.getExternSheetNumber();
result = book.findSheetNameFromExternSheet(indexToExternSheet); result = book.getWorkbook().findSheetNameFromExternSheet(indexToExternSheet);
return result; return result;
} }
@ -77,11 +77,12 @@ public class HSSFName {
public void setNameName(String nameName){ public void setNameName(String nameName){
name.setNameText(nameName); name.setNameText(nameName);
name.setNameTextLength((byte)nameName.length()); name.setNameTextLength((byte)nameName.length());
Workbook wb = book.getWorkbook();
//Check to ensure no other names have the same case-insensitive name //Check to ensure no other names have the same case-insensitive name
for ( int i = book.getNumNames()-1; i >=0; i-- ) for ( int i = wb.getNumNames()-1; i >=0; i-- )
{ {
NameRecord rec = book.getNameRecord(i); NameRecord rec = wb.getNameRecord(i);
if (rec != name) { if (rec != name) {
if (rec.getNameText().equalsIgnoreCase(getNameName())) if (rec.getNameText().equalsIgnoreCase(getNameName()))
throw new IllegalArgumentException("The workbook already contains this name (case-insensitive)"); throw new IllegalArgumentException("The workbook already contains this name (case-insensitive)");
@ -111,7 +112,7 @@ public class HSSFName {
private void setSheetName(String sheetName){ private void setSheetName(String sheetName){
int sheetNumber = book.getSheetIndex(sheetName); int sheetNumber = book.getSheetIndex(sheetName);
short externSheetNumber = book.checkExternSheet(sheetNumber); short externSheetNumber = book.getExternalSheetIndex(sheetNumber);
name.setExternSheetNumber(externSheetNumber); name.setExternSheetNumber(externSheetNumber);
// name.setIndexToSheet(externSheetNumber); // name.setIndexToSheet(externSheetNumber);

View File

@ -53,7 +53,7 @@ public final class HSSFRow implements Comparable {
* reference to containing low level Workbook * reference to containing low level Workbook
*/ */
private Workbook book; private HSSFWorkbook book;
/** /**
* reference to containing Sheet * reference to containing Sheet
@ -75,7 +75,7 @@ public final class HSSFRow implements Comparable {
*/ */
//protected HSSFRow(Workbook book, Sheet sheet, short rowNum) //protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
protected HSSFRow(Workbook book, Sheet sheet, int rowNum) protected HSSFRow(HSSFWorkbook book, Sheet sheet, int rowNum)
{ {
this.rowNum = rowNum; this.rowNum = rowNum;
this.book = book; this.book = book;
@ -99,7 +99,7 @@ public final class HSSFRow implements Comparable {
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
*/ */
protected HSSFRow(Workbook book, Sheet sheet, RowRecord record) protected HSSFRow(HSSFWorkbook book, Sheet sheet, RowRecord record)
{ {
this.book = book; this.book = book;
this.sheet = sheet; this.sheet = sheet;

View File

@ -194,7 +194,7 @@ public final class HSSFSheet {
*/ */
public HSSFRow createRow(int rownum) public HSSFRow createRow(int rownum)
{ {
HSSFRow row = new HSSFRow(book, sheet, rownum); HSSFRow row = new HSSFRow(workbook, sheet, rownum);
addRow(row, true); addRow(row, true);
return row; return row;
@ -209,7 +209,7 @@ public final class HSSFSheet {
private HSSFRow createRowFromRecord(RowRecord row) private HSSFRow createRowFromRecord(RowRecord row)
{ {
HSSFRow hrow = new HSSFRow(book, sheet, row); HSSFRow hrow = new HSSFRow(workbook, sheet, row);
addRow(hrow, false); addRow(hrow, false);
return hrow; return hrow;
@ -394,7 +394,7 @@ public final class HSSFSheet {
//formula fields ( size and data ) //formula fields ( size and data )
String str_formula = obj_validation.getFirstFormula(); String str_formula = obj_validation.getFirstFormula();
FormulaParser fp = new FormulaParser(str_formula, book); FormulaParser fp = new FormulaParser(str_formula, workbook);
fp.parse(); fp.parse();
Stack ptg_arr = new Stack(); Stack ptg_arr = new Stack();
Ptg[] ptg = fp.getRPNPtg(); Ptg[] ptg = fp.getRPNPtg();
@ -418,7 +418,7 @@ public final class HSSFSheet {
if ( obj_validation.getSecondFormula() != null ) if ( obj_validation.getSecondFormula() != null )
{ {
str_formula = obj_validation.getSecondFormula(); str_formula = obj_validation.getSecondFormula();
fp = new FormulaParser(str_formula, book); fp = new FormulaParser(str_formula, workbook);
fp.parse(); fp.parse();
ptg_arr = new Stack(); ptg_arr = new Stack();
ptg = fp.getRPNPtg(); ptg = fp.getRPNPtg();
@ -1264,7 +1264,7 @@ public final class HSSFSheet {
// Since it's a formula cell, process the // Since it's a formula cell, process the
// formula string, and look to see if // formula string, and look to see if
// it contains any references // it contains any references
FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook()); FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook);
fp.parse(); fp.parse();
// Look for references, and update if needed // Look for references, and update if needed
@ -1874,9 +1874,8 @@ public final class HSSFSheet {
HSSFBorderFormatting bordFmt, HSSFBorderFormatting bordFmt,
HSSFPatternFormatting patternFmt) { HSSFPatternFormatting patternFmt) {
Workbook wb = workbook.getWorkbook(); CFRuleRecord rr = CFRuleRecord.create(workbook, comparisonOperation, formula1, formula2);
CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2); return new HSSFConditionalFormattingRule(workbook, rr, fontFmt, bordFmt, patternFmt);
return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
} }
/** /**
@ -1895,9 +1894,8 @@ public final class HSSFSheet {
HSSFFontFormatting fontFmt, HSSFFontFormatting fontFmt,
HSSFBorderFormatting bordFmt, HSSFBorderFormatting bordFmt,
HSSFPatternFormatting patternFmt) { HSSFPatternFormatting patternFmt) {
Workbook wb = workbook.getWorkbook(); CFRuleRecord rr = CFRuleRecord.create(workbook, formula);
CFRuleRecord rr = CFRuleRecord.create(wb, formula); return new HSSFConditionalFormattingRule(workbook, rr, fontFmt, bordFmt, patternFmt);
return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
} }
/** /**

View File

@ -36,6 +36,7 @@ import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg; import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.UnionPtg; import org.apache.poi.hssf.record.formula.UnionPtg;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.poifs.filesystem.*; import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -249,7 +250,7 @@ public class HSSFWorkbook extends POIDocument
} }
for (int i = 0 ; i < workbook.getNumNames() ; ++i){ for (int i = 0 ; i < workbook.getNumNames() ; ++i){
HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i)); HSSFName name = new HSSFName(this, workbook.getNameRecord(i));
names.add(name); names.add(name);
} }
} }
@ -522,6 +523,17 @@ public class HSSFWorkbook extends POIDocument
} }
return -1; return -1;
} }
/**
* 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.
*/
public short getExternalSheetIndex(int internalSheetIndex) {
return workbook.checkExternSheet(internalSheetIndex);
}
/** /**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns * create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
@ -647,6 +659,10 @@ public class HSSFWorkbook extends POIDocument
} }
return retval; return retval;
} }
public SheetReferences getSheetReferences() {
return workbook.getSheetReferences();
}
/** /**
* removes sheet at the given index * removes sheet at the given index
@ -790,7 +806,7 @@ public class HSSFWorkbook extends POIDocument
if (isNewRecord) if (isNewRecord)
{ {
HSSFName newName = new HSSFName(workbook, nameRecord); HSSFName newName = new HSSFName(this, nameRecord);
names.add(newName); names.add(newName);
} }
@ -1101,6 +1117,17 @@ public class HSSFWorkbook extends POIDocument
return result; return result;
} }
/**
* 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
*/
public String resolveNameXText(int refIndex, int definedNameIndex) {
return workbook.resolveNameXText(refIndex, definedNameIndex);
}
/** /**
* Sets the printarea for the sheet provided * Sets the printarea for the sheet provided
@ -1159,7 +1186,7 @@ public class HSSFWorkbook extends POIDocument
if (name == null) return null; if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas //adding one here because 0 indicates a global named region; doesnt make sense for print areas
return name.getAreaReference(workbook); return name.getAreaReference(this);
} }
/** /**
@ -1176,7 +1203,7 @@ public class HSSFWorkbook extends POIDocument
public HSSFName createName(){ public HSSFName createName(){
NameRecord nameRecord = workbook.createName(); NameRecord nameRecord = workbook.createName();
HSSFName newName = new HSSFName(workbook, nameRecord); HSSFName newName = new HSSFName(this, nameRecord);
names.add(newName); names.add(newName);

View File

@ -142,7 +142,7 @@ public final class TestFormulaParser extends TestCase {
assertEquals(true, flag.getValue()); assertEquals(true, flag.getValue());
assertEquals("Y", y.getValue()); assertEquals("Y", y.getValue());
assertEquals("N", n.getValue()); assertEquals("N", n.getValue());
assertEquals("IF", funif.toFormulaString((Workbook) null)); assertEquals("IF", funif.toFormulaString((HSSFWorkbook) null));
assertTrue("Goto ptg exists", goto1.isGoto()); assertTrue("Goto ptg exists", goto1.isGoto());
} }
@ -283,7 +283,7 @@ public final class TestFormulaParser extends TestCase {
} }
public void testMacroFunction() { public void testMacroFunction() {
Workbook w = Workbook.createWorkbook(); HSSFWorkbook w = new HSSFWorkbook();
FormulaParser fp = new FormulaParser("FOO()", w); FormulaParser fp = new FormulaParser("FOO()", w);
fp.parse(); fp.parse();
Ptg[] ptg = fp.getRPNPtg(); Ptg[] ptg = fp.getRPNPtg();
@ -589,8 +589,7 @@ public final class TestFormulaParser extends TestCase {
* a formula consisting of a single no-arg function got rendered without the function braces * a formula consisting of a single no-arg function got rendered without the function braces
*/ */
public void testToFormulaStringZeroArgFunction() { public void testToFormulaStringZeroArgFunction() {
HSSFWorkbook book = new HSSFWorkbook();
Workbook book = Workbook.createWorkbook(); // not really used in this test
Ptg[] ptgs = { Ptg[] ptgs = {
new FuncPtg(10, 0), new FuncPtg(10, 0),
@ -889,7 +888,7 @@ public final class TestFormulaParser extends TestCase {
} }
} }
public void testFuncPtgSelection() { public void testFuncPtgSelection() {
Workbook book = Workbook.createWorkbook(); HSSFWorkbook book = new HSSFWorkbook();
Ptg[] ptgs; Ptg[] ptgs;
ptgs = FormulaParser.parse("countif(A1:A2, 1)", book); ptgs = FormulaParser.parse("countif(A1:A2, 1)", book);
assertEquals(3, ptgs.length); assertEquals(3, ptgs.length);

View File

@ -19,11 +19,11 @@ package org.apache.poi.hssf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting; import org.apache.poi.hssf.record.cf.FontFormatting;
import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.hssf.record.cf.PatternFormatting;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -38,7 +38,7 @@ public final class TestCFRuleRecord extends TestCase
public void testCreateCFRuleRecord () public void testCreateCFRuleRecord ()
{ {
Workbook workbook = Workbook.createWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
CFRuleRecord record = CFRuleRecord.create(workbook, "7"); CFRuleRecord record = CFRuleRecord.create(workbook, "7");
testCFRuleRecord(record); testCFRuleRecord(record);
@ -278,7 +278,7 @@ public final class TestCFRuleRecord extends TestCase
} }
public void testWrite() { public void testWrite() {
Workbook workbook = Workbook.createWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10"); CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10");
PatternFormatting patternFormatting = new PatternFormatting(); PatternFormatting patternFormatting = new PatternFormatting();

View File

@ -24,12 +24,12 @@ import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.RecordFactory; import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
import org.apache.poi.hssf.record.cf.CellRange; import org.apache.poi.hssf.record.cf.CellRange;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Tests the serialization and deserialization of the CFRecordsAggregate * Tests the serialization and deserialization of the CFRecordsAggregate
@ -42,7 +42,7 @@ public final class TestCFRecordsAggregate extends TestCase
public void testCFRecordsAggregate() public void testCFRecordsAggregate()
{ {
Workbook workbook = Workbook.createWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
List recs = new ArrayList(); List recs = new ArrayList();
CFHeaderRecord header = new CFHeaderRecord(); CFHeaderRecord header = new CFHeaderRecord();
CFRuleRecord rule1 = CFRuleRecord.create(workbook, "7"); CFRuleRecord rule1 = CFRuleRecord.create(workbook, "7");

View File

@ -51,13 +51,9 @@ public abstract class AbstractPtgTestCase extends TestCase {
/** /**
* Creates a new Workbook and adds one sheet with the specified name * Creates a new Workbook and adds one sheet with the specified name
*/ */
protected static final Workbook createWorkbookWithSheet(String sheetName) { protected static final HSSFWorkbook createWorkbookWithSheet(String sheetName) {
HSSFWorkbook book = new HSSFWorkbook();
Workbook book = Workbook.createWorkbook(); book.createSheet(sheetName);
// this creates sheet if it doesn't exist
book.checkExternSheet(0);
// TODO - this call alone does not create the sheet even though the javadoc says it does
book.setSheetName(0, sheetName);
return book; return book;
} }
} }

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Tests for Area3DPtg * Tests for Area3DPtg
@ -35,7 +35,7 @@ public final class TestArea3DPtg extends AbstractPtgTestCase {
Area3DPtg target = new Area3DPtg("A1:B1", (short)0); Area3DPtg target = new Area3DPtg("A1:B1", (short)0);
String sheetName = "my sheet"; String sheetName = "my sheet";
Workbook book = createWorkbookWithSheet(sheetName); HSSFWorkbook book = createWorkbookWithSheet(sheetName);
assertEquals("'my sheet'!A1:B1", target.toFormulaString(book)); assertEquals("'my sheet'!A1:B1", target.toFormulaString(book));
book.setSheetName(0, "Sheet1"); book.setSheetName(0, "Sheet1");
@ -44,7 +44,4 @@ public final class TestArea3DPtg extends AbstractPtgTestCase {
book.setSheetName(0, "C64"); book.setSheetName(0, "C64");
assertEquals("'C64'!A1:B1", target.toFormulaString(book)); assertEquals("'C64'!A1:B1", target.toFormulaString(book));
} }
} }

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Tests for Ref3DPtg * Tests for Ref3DPtg
@ -31,7 +31,7 @@ public final class TestRef3DPtg extends AbstractPtgTestCase {
Ref3DPtg target = new Ref3DPtg("A1", (short)0); Ref3DPtg target = new Ref3DPtg("A1", (short)0);
Workbook book = createWorkbookWithSheet("my sheet"); HSSFWorkbook book = createWorkbookWithSheet("my sheet");
assertEquals("'my sheet'!A1", target.toFormulaString(book)); assertEquals("'my sheet'!A1", target.toFormulaString(book));

View File

@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
import org.apache.poi.hssf.record.formula.FuncPtg; import org.apache.poi.hssf.record.formula.FuncPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg; import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Tests parsing of some built-in functions that were not properly * Tests parsing of some built-in functions that were not properly
* registered in POI as bug #44675, #44733 (March/April 2008). * registered in POI as bug #44675, #44733 (March/April 2008).
@ -35,7 +36,7 @@ import org.apache.poi.hssf.record.formula.Ptg;
public final class TestParseMissingBuiltInFuncs extends TestCase { public final class TestParseMissingBuiltInFuncs extends TestCase {
private static Ptg[] parse(String formula) { private static Ptg[] parse(String formula) {
Workbook book = Workbook.createWorkbook(); HSSFWorkbook book = new HSSFWorkbook();
return FormulaParser.parse(formula, book); return FormulaParser.parse(formula, book);
} }
private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) { private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) {
@ -57,7 +58,7 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
assertEquals(expCls, ptgF.getClass()); assertEquals(expCls, ptgF.getClass());
// check that parsed Ptg array converts back to formula text OK // check that parsed Ptg array converts back to formula text OK
Workbook book = Workbook.createWorkbook(); HSSFWorkbook book = new HSSFWorkbook();
String reRenderedFormula = FormulaParser.toFormulaString(book, ptgs); String reRenderedFormula = FormulaParser.toFormulaString(book, ptgs);
assertEquals(formula, reRenderedFormula); assertEquals(formula, reRenderedFormula);
} }

View File

@ -203,7 +203,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
assertEquals(2, ptg.getLastColumn()); assertEquals(2, ptg.getLastColumn());
assertEquals(0, ptg.getFirstRow()); assertEquals(0, ptg.getFirstRow());
assertEquals(65535, ptg.getLastRow()); assertEquals(65535, ptg.getLastRow());
assertEquals("C:C", ptg.toFormulaString(wb.getWorkbook())); assertEquals("C:C", ptg.toFormulaString(wb));
// Will show as C:C, but won't know how many // Will show as C:C, but won't know how many
// rows it covers as we don't have the sheet // rows it covers as we don't have the sheet

View File

@ -211,12 +211,12 @@ public final class TestAreaReference extends TestCase {
Area3DPtg ptgB = (Area3DPtg)def.get(1); Area3DPtg ptgB = (Area3DPtg)def.get(1);
Area3DPtg ptgC = (Area3DPtg)def.get(2); Area3DPtg ptgC = (Area3DPtg)def.get(2);
UnionPtg ptgD = (UnionPtg)def.get(3); UnionPtg ptgD = (UnionPtg)def.get(3);
assertEquals("", ptgA.toFormulaString(workbook)); assertEquals("", ptgA.toFormulaString(wb));
assertEquals(refA, ptgB.toFormulaString(workbook)); assertEquals(refA, ptgB.toFormulaString(wb));
assertEquals(refB, ptgC.toFormulaString(workbook)); assertEquals(refB, ptgC.toFormulaString(wb));
assertEquals(",", ptgD.toFormulaString(workbook)); assertEquals(",", ptgD.toFormulaString(wb));
assertEquals(ref, nr.getAreaReference(workbook)); assertEquals(ref, nr.getAreaReference(wb));
// Check the high level definition // Check the high level definition
int idx = wb.getNameIndex("test"); int idx = wb.getNameIndex("test");