While I don't consider this idea, I like it much better than having the

circular dependancies.  This should fix the bug I caused the other day by
removing Thread Local.
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352765 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-07-15 00:14:40 +00:00
parent b6b940ae56
commit fff3eb8fc5
30 changed files with 142 additions and 89 deletions

View File

@ -77,6 +77,7 @@ import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.formula.*;
import org.apache.poi.hssf.model.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.SheetReferences;
/**
* FormulaViewer - finds formulas in a BIFF8 file and attempts to read them/display
@ -143,7 +144,7 @@ public class FormulaViewer
StringBuffer buf = new StringBuffer();
if (token instanceof ExpPtg) return;
buf.append(name=((OperationPtg) token).toFormulaString());
buf.append(name=((OperationPtg) token).toFormulaString((SheetReferences)null));
buf.append(sep);
switch (token.getPtgClass()) {
case Ptg.CLASS_REF :
@ -212,7 +213,7 @@ public class FormulaViewer
StringBuffer buf = new StringBuffer();
for (int i=0;i<numptgs;i++) {
token = (Ptg) tokens.get(i);
buf.append( token.toFormulaString());
buf.append( token.toFormulaString((SheetReferences)null));
switch (token.getPtgClass()) {
case Ptg.CLASS_REF :
buf.append("(R)");
@ -232,7 +233,7 @@ public class FormulaViewer
private String composeFormula(FormulaRecord record)
{
return FormulaParser.toFormulaString(record.getParsedExpression());
return FormulaParser.toFormulaString((SheetReferences)null,record.getParsedExpression());
}
/**

View File

@ -64,7 +64,6 @@ import java.util.Iterator;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.hssf
.record.*; // normally I don't do this, buy we literally mean ALL
import org.apache.poi.hssf.record.formula.FormulaParser;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.util.IntList;
import org.apache.poi.util.POILogger;

View File

@ -61,10 +61,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import org.apache.poi.hssf.record.*;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Workbook
* Low level model implementation of a Workbook. Provides creational methods
@ -88,7 +91,7 @@ import org.apache.poi.util.POILogFactory;
public class Workbook {
private static final int DEBUG = POILogger.DEBUG;
public static Workbook currentBook = null;
// public static Workbook currentBook = null;
/**
* constant used to set the "codepage" wherever "codepage" is set in records
@ -111,7 +114,7 @@ public class Workbook {
protected SSTRecord sst = null;
/**
* Holds the Extern Sheet with referenced to bound sheets
* Holds the Extern Sheet with references to bound sheets
*/
protected ExternSheetRecord externSheet= null;
@ -1631,6 +1634,18 @@ public class Workbook {
return new EOFRecord();
}
public SheetReferences getSheetReferences() {
SheetReferences refs = new SheetReferences();
if (externSheet != null) {
for (int k = 0; k < externSheet.getNumOfREFStructures(); k++) {
String sheetName = findSheetNameFromExternSheet((short)k);
refs.addSheetReference(sheetName, k);
}
}
return refs;
}
/** fins the sheet name by his extern sheet index
* @param num extern sheet index
* @return sheet name

View File

@ -135,35 +135,38 @@ public class ExternSheetRecord extends Record {
}
}
/** sets the number of the REF structors , that is in Excel file
/**
* sets the number of the REF structors , that is in Excel file
* @param numStruct number of REF structs
*/
public void setNumOfREFStructures(short numStruct) {
field_1_number_of_REF_sturcutres = numStruct;
}
/** return the number of the REF structors , that is in Excel file
/**
* return the number of the REF structors , that is in Excel file
* @return number of REF structs
*/
public short getNumOfREFStructures() {
return field_1_number_of_REF_sturcutres;
}
/** adds REF struct (ExternSheetSubRecord)
/**
* adds REF struct (ExternSheetSubRecord)
* @param rec REF struct
*/
public void addREFRecord(ExternSheetSubRecord rec) {
field_2_REF_structures.add(rec);
}
/** returns the number of REF Record , which is in model
/** returns the number of REF Records, which is in model
* @return number of REF records
*/
public int getNumOfREFRecord() {
public int getNumOfREFRecords() {
return field_2_REF_structures.size();
}
/** return the REF record (ExternSheetSubRecord)
/** returns the REF record (ExternSheetSubRecord)
* @param elem index to place
* @return REF record
*/
@ -178,7 +181,7 @@ public class ExternSheetRecord extends Record {
buffer.append("[EXTERNSHEET]\n");
buffer.append(" numOfRefs = ").append(getNumOfREFStructures()).append("\n");
for (int k=0; k < this.getNumOfREFRecord(); k++) {
for (int k=0; k < this.getNumOfREFRecords(); k++) {
buffer.append("refrec #").append(k).append('\n');
buffer.append(getREFRecordAt(k).toString());
buffer.append("----refrec #").append(k).append('\n');
@ -200,13 +203,13 @@ public class ExternSheetRecord extends Record {
*/
public int serialize(int offset, byte [] data) {
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset,(short)(2 + (getNumOfREFRecord() *6)));
LittleEndian.putShort(data, 2 + offset,(short)(2 + (getNumOfREFRecords() *6)));
LittleEndian.putShort(data, 4 + offset, getNumOfREFStructures());
int pos = 6 ;
for (int k = 0; k < getNumOfREFRecord(); k++) {
for (int k = 0; k < getNumOfREFRecords(); k++) {
ExternSheetSubRecord record = getREFRecordAt(k);
System.arraycopy(record.serialize(), 0, data, pos + offset, 6);
@ -216,7 +219,7 @@ public class ExternSheetRecord extends Record {
}
public int getRecordSize() {
return 4 + 2 + getNumOfREFRecord() * 6;
return 4 + 2 + getNumOfREFRecords() * 6;
}
/**

View File

@ -63,6 +63,7 @@ import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.Ref3DPtg;
import java.util.List;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Title: Name Record (aka Named Range) <P>
@ -501,16 +502,16 @@ public class NameRecord extends Record {
/** gets the reference , the area only (range)
* @return area reference
*/
public String getAreaReference(){
public String getAreaReference(SheetReferences refs){
if (field_13_name_definition == null) return "#REF!";
Ptg ptg = (Ptg) field_13_name_definition.peek();
String result = "";
if (ptg.getClass() == Area3DPtg.class){
result = ((Area3DPtg) ptg).toFormulaString();
result = ((Area3DPtg) ptg).toFormulaString(refs);
} else if (ptg.getClass() == Ref3DPtg.class){
result = ((Ref3DPtg) ptg).toFormulaString();
result = ((Ref3DPtg) ptg).toFormulaString(refs);
}
return result;

View File

@ -1,6 +1,8 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.BinaryTree;
import org.apache.poi.hssf.util.SheetReferences;
/**
* This class provides the base functionality for Excel sheet functions
* There are two kinds of function Ptgs - tFunc and tFuncVar
@ -46,7 +48,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
return lookupName(field_2_fnc_index);
}
public String toFormulaString() {
public String toFormulaString(SheetReferences refs) {
return getName();
}
@ -802,7 +804,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
return returnClass;
}
protected byte getParameterClass(int index) {
public byte getParameterClass(int index) {
try {
return paramClass[index];
} catch (ArrayIndexOutOfBoundsException aioobe) {

View File

@ -62,6 +62,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Addition operator PTG the "+" binomial operator. If you need more
* explanation than that then well...We really can't help you here.
@ -78,7 +80,7 @@ public class AddPtg
/** Creates new AddPtg */
protected AddPtg()
public AddPtg()
{
}
@ -110,7 +112,7 @@ public class AddPtg
}
/** Implementation of method from Ptg */
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "+";
}
@ -120,7 +122,7 @@ public class AddPtg
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString());
buffer.append(ADD);
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -59,6 +59,7 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.util.BitField;
@ -88,7 +89,7 @@ public class Area3DPtg extends Ptg
/** Creates new AreaPtg */
public Area3DPtg() {}
protected Area3DPtg(String arearef, short externIdx) {
public Area3DPtg(String arearef, short externIdx) {
AreaReference ar = new AreaReference(arearef);
setFirstRow((short)ar.getCells()[0].getRow());
@ -286,12 +287,11 @@ public class Area3DPtg extends Ptg
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
StringBuffer retval = new StringBuffer();
Object book = Workbook.currentBook;
if (book != null) {
retval.append(((Workbook) book).findSheetNameFromExternSheet(this.field_1_index_extern_sheet));
if (refs != null) {
retval.append(refs.getSheetName(this.field_1_index_extern_sheet));
retval.append('!');
}
retval.append((new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString());

View File

@ -65,6 +65,7 @@ import org.apache.poi.util.BitField;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@ -87,7 +88,7 @@ public class AreaPtg
protected AreaPtg(String arearef) {
public AreaPtg(String arearef) {
AreaReference ar = new AreaReference(arearef);
setFirstRow((short)ar.getCells()[0].getRow());
setFirstColumn((short)ar.getCells()[0].getCol());
@ -301,7 +302,7 @@ public class AreaPtg
field_4_last_column = column;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return (new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString() + ":" +
(new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString();

View File

@ -60,6 +60,8 @@
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
@ -196,7 +198,7 @@ public class AttrPtg
return operands[ 0 ];
}
else {
return toFormulaString() + "(" + operands[ 0 ] + ")";
return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")";
}
}
@ -211,7 +213,7 @@ public class AttrPtg
return -1;
}
public String toFormulaString() {
public String toFormulaString(SheetReferences refs) {
if(semiVolatile.isSet(field_1_options)) {
return "ATTR(semiVolatile)";
}

View File

@ -62,6 +62,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
@ -81,7 +83,7 @@ public class ConcatPtg
// doesn't need anything
}
protected ConcatPtg() {
public ConcatPtg() {
}
@ -105,7 +107,7 @@ public class ConcatPtg
return 2;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return CONCAT;
}

View File

@ -62,9 +62,11 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
* This PTG implements the standard binomial divide "/"
* @author Andrew C. Oliver acoliver at apache dot org
*/
public class DividePtg
@ -75,7 +77,7 @@ public class DividePtg
/** Creates new AddPtg */
protected DividePtg()
public DividePtg()
{
}
@ -105,7 +107,7 @@ public class DividePtg
return 2;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "/";
}
@ -114,7 +116,7 @@ public class DividePtg
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString());
buffer.append(toFormulaString((SheetReferences)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -60,6 +60,8 @@
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
@ -73,7 +75,7 @@ public class ExpPtg
/** Creates new ExpPtg */
protected ExpPtg()
public ExpPtg()
{
}
@ -92,7 +94,7 @@ public class ExpPtg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "NO IDEA SHARED FORMULA EXP PTG";
}

View File

@ -16,7 +16,7 @@ public class FuncVarPtg extends AbstractFunctionPtg{
/**
* Create a function ptg from a string tokenised by the parser
*/
protected FuncVarPtg(String pName, byte pNumOperands) {
public FuncVarPtg(String pName, byte pNumOperands) {
field_1_num_args = pNumOperands;
field_2_fnc_index = lookupIndex(pName);
try{

View File

@ -61,11 +61,12 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Integer (short intger)
* Stores a (java) short value in a formula
* @author andy
* @author Andrew C. Oliver (acoliver at apache dot org)
*/
public class IntPtg
@ -85,7 +86,7 @@ public class IntPtg
// IntPtg should be able to create itself, shouldnt have to call setValue
protected IntPtg(String formulaToken) {
public IntPtg(String formulaToken) {
setValue(Short.parseShort(formulaToken));
}
@ -110,7 +111,7 @@ public class IntPtg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "" + getValue();
}

View File

@ -61,6 +61,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
@ -116,7 +117,7 @@ public class MemErrPtg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "ERR#";
}

View File

@ -54,6 +54,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Missing Function Arguments
@ -67,7 +68,7 @@ public class MissingArgPtg
private final static int SIZE = 1;
public final static byte sid = 0x16;
protected MissingArgPtg()
public MissingArgPtg()
{
}
@ -89,7 +90,7 @@ public class MissingArgPtg
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return " ";
}

View File

@ -61,10 +61,11 @@
package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
* Implements the standard mathmatical multiplication - *
* @author Andrew C. Oliver (acoliver at apache dot org)
*/
public class MultiplyPtg
@ -77,7 +78,7 @@ public class MultiplyPtg
/** Creates new AddPtg */
protected MultiplyPtg()
public MultiplyPtg()
{
}
@ -112,7 +113,7 @@ public class MultiplyPtg
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "*";
}
@ -121,9 +122,9 @@ public class MultiplyPtg
{
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ].toFormulaString());
buffer.append(operands[ 0 ].toFormulaString((SheetReferences)null));
buffer.append("*");
buffer.append(operands[ 1 ].toFormulaString());
buffer.append(operands[ 1 ].toFormulaString((SheetReferences)null));
return buffer.toString();
}
@ -131,7 +132,7 @@ public class MultiplyPtg
StringBuffer buffer = new StringBuffer();
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString());
buffer.append(toFormulaString((SheetReferences)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -61,6 +61,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
@ -78,7 +79,7 @@ public class NamePtg
/** Creates new NamePtg */
protected NamePtg(String name)
public NamePtg(String name)
{
//TODO
}
@ -102,7 +103,7 @@ public class NamePtg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "NO IDEA - NAME";
}

View File

@ -55,7 +55,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Number
* Stores a floating point value in a formula
@ -82,7 +82,7 @@ public class NumberPtg
* that calls this method.
* @param value : String representation of a floating point number
*/
protected NumberPtg(String value) {
public NumberPtg(String value) {
setValue(Double.parseDouble(value));
}
@ -109,7 +109,7 @@ public class NumberPtg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "" + getValue();
}

View File

@ -57,6 +57,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
* While formula tokens are stored in RPN order and thus do not need parenthesis for
* precedence reasons, Parenthesis tokens ARE written to ensure that user entered
@ -72,7 +74,7 @@ public class ParenthesisPtg
private final static int SIZE = 1;
public final static byte sid = 0x15;
protected ParenthesisPtg()
public ParenthesisPtg()
{
}
@ -104,7 +106,7 @@ public class ParenthesisPtg
return 1;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "()";
}

View File

@ -62,6 +62,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
@ -75,7 +77,7 @@ public class PowerPtg
/** Creates new AddPtg */
protected PowerPtg()
public PowerPtg()
{
}
@ -105,7 +107,7 @@ public class PowerPtg
return 2;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "^";
}
@ -115,7 +117,7 @@ public class PowerPtg
buffer.append(operands[ 0 ]);
buffer.append(toFormulaString());
buffer.append(toFormulaString((SheetReferences)null));
buffer.append(operands[ 1 ]);
return buffer.toString();
}

View File

@ -63,6 +63,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.List;
import java.util.ArrayList;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
@ -295,7 +297,7 @@ public abstract class Ptg
/**
* return a string representation of this token alone
*/
public abstract String toFormulaString();
public abstract String toFormulaString(SheetReferences refs);
/**
* dump a debug representation (hexdump) to a strnig
*/

View File

@ -57,8 +57,10 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.model.Workbook;
@ -89,7 +91,7 @@ public class Ref3DPtg extends Ptg {
field_3_column = LittleEndian.getShort(data, 4 + offset);
}
protected Ref3DPtg(String cellref, short externIdx ) {
public Ref3DPtg(String cellref, short externIdx ) {
CellReference c= new CellReference(cellref);
setRow((short) c.getRow());
setColumn((short) c.getCol());
@ -190,11 +192,10 @@ public class Ref3DPtg extends Ptg {
}
public String toFormulaString() {
public String toFormulaString(SheetReferences refs) {
StringBuffer retval = new StringBuffer();
Object book = Workbook.currentBook;
if (book != null) {
retval.append(((Workbook) book).findSheetNameFromExternSheet(this.field_1_index_extern_sheet));
if (refs != null) {
retval.append(refs.getSheetName((int)this.field_1_index_extern_sheet));
retval.append('!');
}
retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString());

View File

@ -64,6 +64,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.util.SheetReferences;
/**
* ReferencePtg - handles references (such as A1, A2, IA4)
@ -86,7 +87,7 @@ public class ReferencePtg extends Ptg
* Takes in a String represnetation of a cell reference and fills out the
* numeric fields.
*/
protected ReferencePtg(String cellref) {
public ReferencePtg(String cellref) {
CellReference c= new CellReference(cellref);
setRow((short) c.getRow());
setColumn((short) c.getCol());
@ -175,7 +176,7 @@ public class ReferencePtg extends Ptg
return SIZE;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
return (new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString();

View File

@ -56,6 +56,8 @@ package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Number
* Stores a String value in a formula value stored in the format <length 2 bytes>char[]
@ -81,7 +83,7 @@ public class StringPtg
* that calls this method.
* @param value : String representation of a floating point number
*/
protected StringPtg(String value) {
public StringPtg(String value) {
setValue(value);
}
@ -110,7 +112,7 @@ public class StringPtg
return field_1_value.length() + 3;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return getValue();
}

View File

@ -61,6 +61,7 @@
package org.apache.poi.hssf.record.formula;
import java.util.List;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
@ -73,7 +74,7 @@ public class SubtractPtg
public final static int SIZE = 1;
public final static byte sid = 0x04;
protected SubtractPtg()
public SubtractPtg()
{
}
@ -103,7 +104,7 @@ public class SubtractPtg
return 2;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "-";
}

View File

@ -60,6 +60,8 @@
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.SheetReferences;
/**
*
* @author andy
@ -91,7 +93,7 @@ public class UnknownPtg
return size;
}
public String toFormulaString()
public String toFormulaString(SheetReferences refs)
{
return "UNKNOWN";
}

View File

@ -62,6 +62,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.FormulaParser;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.FormulaRecord;
@ -71,8 +72,9 @@ import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.BoolErrRecord;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.util.SheetReferences;
import org.apache.poi.hssf.record.formula.FormulaParser;
//import org.apache.poi.hssf.record.formula.FormulaParser;
import java.util.Date;
import java.util.Calendar;
@ -693,7 +695,7 @@ public class HSSFCell
}
public void setCellFormula(String formula) {
Workbook.currentBook=book;
//Workbook.currentBook=book;
if (formula==null) {
setCellType(CELL_TYPE_BLANK,false);
} else {
@ -712,14 +714,15 @@ public class HSSFCell
rec.pushExpressionToken(ptg[ k ]);
}
rec.setExpressionLength(( short ) size);
Workbook.currentBook = null;
//Workbook.currentBook = null;
}
}
public String getCellFormula() {
Workbook.currentBook=book;
String retval = FormulaParser.toFormulaString(((FormulaRecord)record).getParsedExpression());
Workbook.currentBook=null;
//Workbook.currentBook=book;
SheetReferences refs = book.getSheetReferences();
String retval = FormulaParser.toFormulaString(refs, ((FormulaRecord)record).getParsedExpression());
//Workbook.currentBook=null;
return retval;
}

View File

@ -64,6 +64,7 @@ import org.apache.poi.util.POILogger;
import java.util.Iterator;
import java.util.TreeMap;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.SheetReferences;
/**
* Title: High Level Represantion of Named Range <P>
@ -137,10 +138,9 @@ public class HSSFName {
*/
public String getReference() {
Workbook.currentBook=book;
String result;
result = name.getAreaReference();
Workbook.currentBook=null;
SheetReferences refs = book.getSheetReferences();
result = name.getAreaReference(refs);
return result;
}