ASF Bugzilla – Attachment 18405 Details for
Bug 38396
Formula Evaluator number range .
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Corrects deficiencies in previously submitted patch
38396.PATCH (text/plain), 7.71 KB, created by
Amol Deshmukh
on 2006-06-05 16:57:24 UTC
(
hide
)
Description:
Corrects deficiencies in previously submitted patch
Filename:
MIME Type:
Creator:
Amol Deshmukh
Created:
2006-06-05 16:57:24 UTC
Size:
7.71 KB
patch
obsolete
>Index: C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java >=================================================================== >--- C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (revision 411790) >+++ C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (working copy) >@@ -597,8 +597,9 @@ > } else { > setCellType(CELL_TYPE_FORMULA,false,row,col,styleIndex); > FormulaRecordAggregate rec = (FormulaRecordAggregate) record; >- rec.getFormulaRecord().setOptions(( short ) 2); >- rec.getFormulaRecord().setValue(0); >+ FormulaRecord frec = rec.getFormulaRecord(); >+ frec.setOptions(( short ) 2); >+ frec.setValue(0); > > //only set to default if there is no extended format index already set > if (rec.getXFIndex() == (short)0) rec.setXFIndex(( short ) 0x0f); >@@ -607,9 +608,15 @@ > Ptg[] ptg = fp.getRPNPtg(); > int size = 0; > //System.out.println("got Ptgs " + ptg.length); >+ >+ // clear the Ptg Stack >+ for (int i=0, iSize=frec.getNumberOfExpressionTokens(); i<iSize; i++) { >+ frec.popExpressionToken(); >+ } >+ > for (int k = 0; k < ptg.length; k++) { > size += ptg[ k ].getSize(); >- rec.getFormulaRecord().pushExpressionToken(ptg[ k ]); >+ frec.pushExpressionToken(ptg[ k ]); > } > rec.getFormulaRecord().setExpressionLength(( short ) size); > //Workbook.currentBook = null; >Index: C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java >=================================================================== >--- C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java (revision 411790) >+++ C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java (working copy) >@@ -229,16 +229,35 @@ > } > > >+ /** Get the exponent for numbers of form 1.3E21 */ >+ private String GetExponent() { >+ StringBuffer retval = new StringBuffer(); >+ String sign = ""; >+ GetChar(); >+ if ('-' == look) { >+ sign = "-"; >+ GetChar(); >+ } >+ while (IsDigit(look)) { >+ retval.append(look); >+ GetChar(); >+ } >+ if (retval.length() > 0) { >+ retval.insert(0, sign); >+ } >+ return retval.toString(); >+ } >+ > /** Get a Number */ > private String GetNum() { >- String Value =""; >+ StringBuffer value = new StringBuffer(); > if (!IsDigit(look)) Expected("Integer"); > while (IsDigit(look)){ >- Value = Value + look; >+ value.append(look); > GetChar(); > } > SkipWhite(); >- return Value; >+ return value.toString(); > } > > /** Output a String with Tab */ >@@ -482,8 +501,18 @@ > Match('.'); > String decimalPart = null; > if (IsDigit(look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234." >+ if ('E' == look) { >+ String exponent = GetExponent(); >+ number += 'E' + exponent; >+ } > tokens.add(new NumberPtg(number)); >- } else { >+ } >+ else if ('E' == look) { >+ String exponent = GetExponent(); >+ number += 'E'+exponent; >+ tokens.add(new NumberPtg(number)); >+ } >+ else { > tokens.add(getNumberPtgFromString(number)); //TODO:what if the number is too big to be a short? ..add factory to return Int or Number! > } > } >Index: C:/D/eclipseworkspaces/Trial/jakarta-poi/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java >=================================================================== >--- C:/D/eclipseworkspaces/Trial/jakarta-poi/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (revision 411790) >+++ C:/D/eclipseworkspaces/Trial/jakarta-poi/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (working copy) >@@ -17,6 +17,8 @@ > > package org.apache.poi.hssf.model; > >+import java.io.FileOutputStream; >+ > import junit.framework.TestCase; > > import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; >@@ -38,6 +40,7 @@ > import org.apache.poi.hssf.record.formula.UnaryMinusPtg; > import org.apache.poi.hssf.record.formula.UnaryPlusPtg; > import org.apache.poi.hssf.usermodel.HSSFCell; >+import org.apache.poi.hssf.usermodel.HSSFRichTextString; > import org.apache.poi.hssf.usermodel.HSSFRow; > import org.apache.poi.hssf.usermodel.HSSFSheet; > import org.apache.poi.hssf.usermodel.HSSFWorkbook; >@@ -404,7 +407,70 @@ > > } > >- public static void main(String [] args) { >+ // bug 38396 : Formula with exponential numbers not parsed correctly. >+ public void testExponentialParsing() { >+ FormulaParser fp = new FormulaParser("1.3E21/2", null); >+ fp.parse(); >+ Ptg[] ptgs = fp.getRPNPtg(); >+ assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); >+ assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); >+ assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); >+ assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); >+ >+ fp = new FormulaParser("1322E21/2", null); >+ fp.parse(); >+ ptgs = fp.getRPNPtg(); >+ assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); >+ assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); >+ assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); >+ assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); >+ >+ fp = new FormulaParser("1.3E1/2", null); >+ fp.parse(); >+ ptgs = fp.getRPNPtg(); >+ assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); >+ assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg)); >+ assertTrue("IntPtg",(ptgs[1] instanceof IntPtg)); >+ assertTrue("DividePtg",(ptgs[2] instanceof DividePtg)); >+ >+ } >+ public void testExponentialInSheet() throws Exception { >+ HSSFWorkbook wb = new HSSFWorkbook(); >+ >+ wb.createSheet("Cash_Flow");; >+ >+ HSSFSheet sheet = wb.createSheet("Test"); >+ HSSFRow row = sheet.createRow(0); >+ HSSFCell cell = row.createCell((short)0); >+ String formula = null; >+ >+ cell.setCellFormula("1.3E21/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "1.3E21/3", formula); >+ >+ cell.setCellFormula("1322E21/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "1.322E24/3", formula); >+ >+ cell.setCellFormula("1.3E1/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "13.0/3", formula); >+ >+ cell.setCellFormula("1.3E-4/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "1.3E-4/3", formula); >+ >+ cell.setCellFormula("13E-15/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "1.3E-14/3", formula); >+ >+ cell.setCellFormula("1.3E3/3"); >+ formula = cell.getCellFormula(); >+ assertEquals("Exponential formula string", "1300.0/3", formula); >+ >+ } >+ >+ public static void main(String [] args) { > System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); > junit.textui.TestRunner.run(TestFormulaParser.class); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 38396
:
17628
|
17629
|
18403
| 18405