removed use of deprecated calls to get the String value of a cell
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@477928 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fd3bbdbd1c
commit
471bb226a4
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -75,7 +74,6 @@ import org.apache.poi.hssf.record.formula.eval.SubtractEval;
|
|||||||
import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
|
import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
|
import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||||
@ -90,8 +88,6 @@ public class HSSFFormulaEvaluator {
|
|||||||
|
|
||||||
private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class };
|
private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class };
|
||||||
|
|
||||||
private static final Class[] AREA_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval[].class };
|
|
||||||
|
|
||||||
private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval[].class };
|
private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval[].class };
|
||||||
|
|
||||||
private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval.class };
|
private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval.class };
|
||||||
@ -186,7 +182,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
retval = new CellValue(HSSFCell.CELL_TYPE_STRING);
|
retval = new CellValue(HSSFCell.CELL_TYPE_STRING);
|
||||||
retval.setStringValue(cell.getStringCellValue());
|
retval.setRichTextStringValue(cell.getRichStringCellValue());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +217,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
cell.setCellValue(cv.getNumberValue());
|
cell.setCellValue(cv.getNumberValue());
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
cell.setCellValue(cv.getStringValue());
|
cell.setCellValue(cv.getRichTextStringValue());
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_BLANK:
|
case HSSFCell.CELL_TYPE_BLANK:
|
||||||
break;
|
break;
|
||||||
@ -333,7 +329,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex());
|
HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex());
|
||||||
HSSFRow row = sheet.getRow(rownum);
|
HSSFRow row = sheet.getRow(rownum);
|
||||||
HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
|
HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
|
||||||
pushRef3DEval(ptg, stack, cell, row, sheet, workbook);
|
pushRef3DEval(ptg, stack, cell, row, xsheet, workbook);
|
||||||
}
|
}
|
||||||
else if (ptgs[i] instanceof AreaPtg) {
|
else if (ptgs[i] instanceof AreaPtg) {
|
||||||
AreaPtg ap = (AreaPtg) ptgs[i];
|
AreaPtg ap = (AreaPtg) ptgs[i];
|
||||||
@ -364,7 +360,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
HSSFRow row = sheet.getRow(x);
|
HSSFRow row = sheet.getRow(x);
|
||||||
for (short y = col0; row != null && y < col1 + 1; y++) {
|
for (short y = col0; row != null && y < col1 + 1; y++) {
|
||||||
values[(x - row0) * (col1 - col0 + 1) + (y - col0)] =
|
values[(x - row0) * (col1 - col0 + 1) + (y - col0)] =
|
||||||
getEvalForCell(row.getCell(y), row, sheet, workbook);
|
getEvalForCell(row.getCell(y), row, xsheet, workbook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AreaEval ae = new Area3DEval(a3dp, values);
|
AreaEval ae = new Area3DEval(a3dp, values);
|
||||||
@ -475,7 +471,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
retval = new NumberEval(cell.getNumericCellValue());
|
retval = new NumberEval(cell.getNumericCellValue());
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
retval = new StringEval(cell.getStringCellValue());
|
retval = new StringEval(cell.getRichStringCellValue().getString());
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_FORMULA:
|
case HSSFCell.CELL_TYPE_FORMULA:
|
||||||
retval = internalEvaluate(cell, row, sheet, workbook);
|
retval = internalEvaluate(cell, row, sheet, workbook);
|
||||||
@ -511,7 +507,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
|
stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
stack.push(new Ref2DEval(ptg, new StringEval(cell.getStringCellValue()), false));
|
stack.push(new Ref2DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()), false));
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_FORMULA:
|
case HSSFCell.CELL_TYPE_FORMULA:
|
||||||
stack.push(new Ref2DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
|
stack.push(new Ref2DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
|
||||||
@ -548,7 +544,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
|
stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
stack.push(new Ref3DEval(ptg, new StringEval(cell.getStringCellValue()), false));
|
stack.push(new Ref3DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()), false));
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_FORMULA:
|
case HSSFCell.CELL_TYPE_FORMULA:
|
||||||
stack.push(new Ref3DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
|
stack.push(new Ref3DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
|
||||||
@ -576,7 +572,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
*/
|
*/
|
||||||
public static final class CellValue {
|
public static final class CellValue {
|
||||||
private int cellType;
|
private int cellType;
|
||||||
private String stringValue;
|
private HSSFRichTextString richTextStringValue;
|
||||||
private double numberValue;
|
private double numberValue;
|
||||||
private boolean booleanValue;
|
private boolean booleanValue;
|
||||||
private byte errorValue;
|
private byte errorValue;
|
||||||
@ -614,16 +610,20 @@ public class HSSFFormulaEvaluator {
|
|||||||
this.numberValue = numberValue;
|
this.numberValue = numberValue;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return Returns the stringValue.
|
* @return Returns the stringValue. This method is deprecated, use
|
||||||
|
* getRichTextStringValue instead
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public String getStringValue() {
|
public String getStringValue() {
|
||||||
return stringValue;
|
return richTextStringValue.getString();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param stringValue The stringValue to set.
|
* @param stringValue The stringValue to set. This method is deprecated, use
|
||||||
|
* getRichTextStringValue instead.
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public void setStringValue(String stringValue) {
|
public void setStringValue(String stringValue) {
|
||||||
this.stringValue = stringValue;
|
this.richTextStringValue = new HSSFRichTextString(stringValue);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return Returns the cellType.
|
* @return Returns the cellType.
|
||||||
@ -643,29 +643,17 @@ public class HSSFFormulaEvaluator {
|
|||||||
public void setErrorValue(byte errorValue) {
|
public void setErrorValue(byte errorValue) {
|
||||||
this.errorValue = errorValue;
|
this.errorValue = errorValue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manual testing... needs "the" c:/temp/test1.xls file to be present.
|
* @return Returns the richTextStringValue.
|
||||||
*
|
|
||||||
* @param args
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public HSSFRichTextString getRichTextStringValue() {
|
||||||
String FILE_NAME = "c:/temp/test1.xls";
|
return richTextStringValue;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(FILE_NAME);
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fis);
|
|
||||||
fis.close();
|
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
|
||||||
HSSFFormulaEvaluator instance = new HSSFFormulaEvaluator(sheet, wb);
|
|
||||||
|
|
||||||
for (int rn = 1, rnSize = 4; rn <= rnSize; rn++) {
|
|
||||||
HSSFRow row = sheet.getRow(rn);
|
|
||||||
for (int cn = 5, cnSize = 7; cn <= cnSize; cn++) {
|
|
||||||
HSSFCell cell = row.getCell((short) cn);
|
|
||||||
System.out.println(new CellReference(rn, cn).toString() + ": " + instance.evaluate(cell));
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param richTextStringValue The richTextStringValue to set.
|
||||||
|
*/
|
||||||
|
public void setRichTextStringValue(HSSFRichTextString richTextStringValue) {
|
||||||
|
this.richTextStringValue = richTextStringValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user