Bug 42618 - Problem reading excel cell formula
Summary: Problem reading excel cell formula
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All Windows XP
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-08 08:03 UTC by nshashank1982
Modified: 2008-05-01 14:27 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nshashank1982 2007-06-08 08:03:52 UTC
I am trying to read a formula as is from the excel file.

The formula is =CHOOSE(2,A2,A3,A4)

But I am getting the following error.

Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: 
Unable to construct record instance
        at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java:191)
        at org.apache.poi.hssf.record.RecordFactory.createRecords
(RecordFactory.java:115)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:205)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:257)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:238)
        at excelFileReader.ParseExcel.main(ParseExcel.java:14)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown 
Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown 
Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java:179)
        ... 5 more
Caused by: org.apache.poi.hssf.record.RecordFormatException: 
java.lang.UnsupportedOperationException:  Unknown Ptg in Formula: 0x0 (0)
        at org.apache.poi.hssf.record.FormulaRecord.fillFields
(FormulaRecord.java:109)
        at org.apache.poi.hssf.record.Record.<init>(Record.java:56)
        at org.apache.poi.hssf.record.FormulaRecord.<init>
(FormulaRecord.java:89)
        ... 10 more
Caused by: java.lang.UnsupportedOperationException:  Unknown Ptg in Formula: 
0x0 (0)
        at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:357)
        at org.apache.poi.hssf.record.formula.Ptg.createParsedExpressionTokens
(Ptg.java:98)
        at org.apache.poi.hssf.record.FormulaRecord.fillFields
(FormulaRecord.java:107)
        ... 12 more
Comment 1 Nick Burch 2008-01-25 08:37:41 UTC
I'm unable to replicate this using poi from svn trunk

I've created a file with the supplied formula in it, and written a test that
tries to load the file with the formula. This works just fine, so I assume this
bug has been fixed since whatever version you're using.

If it's still there for you with a svn trunk checkout, please re-open the bug
and upload your problem file
Comment 2 Yegor Kozlov 2008-01-25 11:23:05 UTC
Nick, are you sure the test passes? 

yegor@yegornb ~/poi
$  ant -Dtestcase=org.apache.poi.hssf.usermodel.TestBugs single-test
Buildfile: build.xml

-test-property-check:

check-jars:

fetch-jars:

init:

with.clover:

fail-unless-xslt-is-available:

fail-xslt:

compile-main:
    [javac] Compiling 1 source file to
D:\java\apache\jakarta-poi\poi\trunk\build\classes

single-test:
    [junit] Running org.apache.poi.hssf.usermodel.TestBugs
    [junit] Test
    [junit] Tests run: 49, Failures: 0, Errors: 1, Time elapsed: 2.625 sec
    [junit] Testsuite: org.apache.poi.hssf.usermodel.TestBugs
    [junit] Tests run: 49, Failures: 0, Errors: 1, Time elapsed: 2.625 sec
    [junit] ------------- Standard Output ---------------
    [junit] Test
    [junit] ------------- ---------------- ---------------

    [junit] Testcase: test15228 took 1.406 sec
    [junit] Testcase: test13796 took 0 sec
    [junit] Testcase: test23094 took 0.016 sec
    [junit] Testcase: test15353 took 0 sec
    [junit] Testcase: test14460 took 0 sec
    [junit] Testcase: test14330 took 0.015 sec
    [junit] Testcase: test15375 took 0 sec
    [junit] Testcase: test15375_2 took 0.328 sec
    [junit] Testcase: test22568 took 0.063 sec
    [junit] Testcase: test15556 took 0.031 sec
    [junit] Testcase: test22742 took 0.016 sec
    [junit] Testcase: test12561_1 took 0.015 sec
    [junit] Testcase: test12561_2 took 0 sec
    [junit] Testcase: test12843_1 took 0.157 sec
    [junit] Testcase: test12843_2 took 0.015 sec
    [junit] Testcase: test13224 took 0 sec
    [junit] Testcase: test19599 took 0.032 sec
    [junit] Testcase: test24215 took 0.015 sec
    [junit] Testcase: test18800 took 0 sec
    [junit] Testcase: test22720 took 0 sec
    [junit] Testcase: testUnicodeStringFormulaRead took 0 sec
    [junit] Testcase: test32822 took 0.016 sec
    [junit] Testcase: test15573 took 0 sec
    [junit] Testcase: test27852 took 0 sec
    [junit] Testcase: test33082 took 0.015 sec
    [junit] Testcase: test34775 took 0.016 sec
    [junit] Testcase: test37630 took 0 sec
    [junit] Testcase: test25183 took 0.016 sec
    [junit] Testcase: test26100 took 0 sec
    [junit] Testcase: test27933 took 0.015 sec
    [junit] Testcase: test29206 took 0 sec
    [junit] Testcase: test29675 took 0 sec
    [junit] Testcase: test29942 took 0.047 sec
    [junit] Testcase: test29982 took 0.063 sec
    [junit] Testcase: test30540 took 0.015 sec
    [junit] Testcase: test31749 took 0.047 sec
    [junit] Testcase: test31979 took 0.016 sec
    [junit] Testcase: test35564 took 0.031 sec
    [junit] Testcase: test35565 took 0.031 sec
    [junit] Testcase: test37376 took 0 sec
    [junit] Testcase: test40285 took 0 sec
    [junit] Testcase: test40296 took 0 sec
    [junit] Testcase: test38266 took 0.016 sec
    [junit] Testcase: test40738 took 0 sec
    [junit] Testcase: test44200 took 0 sec
    [junit] Testcase: test44201 took 0.016 sec
    [junit] Testcase: test37684 took 0.046 sec
    [junit] Testcase: test41139 took 0.032 sec
    [junit] Testcase: test42618 took 0 sec
    [junit]     Caused an ERROR
    [junit] Unable to construct record instance
    [junit] org.apache.poi.hssf.record.RecordFormatException: Unable to
construct record instance
    [junit]     at
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:199)
    [junit]     at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:117)
    [junit]     at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:207)
    [junit]     at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:259)
    [junit]     at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:240)
    [junit]     at
org.apache.poi.hssf.usermodel.TestBugs.test42618(TestBugs.java:1019)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [junit]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
    [junit]     at junit.framework.TestCase.runTest(TestCase.java:154)
    [junit]     at junit.framework.TestCase.runBare(TestCase.java:127)
    [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run(TestCase.java:118)
    [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:208)
    [junit]     at junit.framework.TestSuite.run(TestSuite.java:203)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.
java:289)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java
:1061)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:676
)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.j
ava:1413)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:633
)
    [junit]     at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [junit]     at org.apache.tools.ant.Task.perform(Task.java:364)
    [junit]     at org.apache.tools.ant.Target.execute(Target.java:341)
    [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
    [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
    [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
    [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:673)
    [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:188)
    [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
    [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
    [junit] Caused by: java.lang.reflect.InvocationTargetException
    [junit]     at
sun.reflect.GeneratedConstructorAccessor19.newInstance(Unknown Source)
    [junit]     at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAc
cessorImpl.java:27)
    [junit]     at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    [junit]     at
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:187)
    [junit]     ... 32 more
    [junit] Caused by: org.apache.poi.hssf.record.RecordFormatException:
java.lang.UnsupportedOperat
ionException:  Unknown Ptg in Formula: 0x0 (0)
    [junit]     at
org.apache.poi.hssf.record.FormulaRecord.fillFields(FormulaRecord.java:109)
    [junit]     at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
    [junit]     at
org.apache.poi.hssf.record.FormulaRecord.<init>(FormulaRecord.java:89)
    [junit]     ... 36 more
    [junit] Caused by: java.lang.UnsupportedOperationException:  Unknown Ptg in
Formula: 0x0 (0)
    [junit]     at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:357)
    [junit]     at
org.apache.poi.hssf.record.formula.Ptg.createParsedExpressionTokens(Ptg.java:98)
    [junit]     at
org.apache.poi.hssf.record.FormulaRecord.fillFields(FormulaRecord.java:107)
    [junit]     ... 38 more

    [junit] Test org.apache.poi.hssf.usermodel.TestBugs FAILED

BUILD SUCCESSFUL
Total time: 5 seconds

It blocks the release and I had to comment it out.

Yegor
Comment 3 Nick Burch 2008-01-28 04:18:53 UTC
I think eclipse hates me - it was claiming that test was passing :(

This now opens properly - had to make some tweaks to the Ptg generation, and
write a new test for how we parse the low level FormulaRecord in this case
Comment 4 Peter J. Krum 2008-05-01 12:16:25 UTC
What version of POI is this bug fixed in?
Comment 5 Josh Micich 2008-05-01 14:27:02 UTC
(In reply to comment #4)
> What version of POI is this bug fixed in?
> 

Nick seems to have applied the last change on Jan-28 (svn r615859), which was between 3.0.2-BETA2 and 3.0.2-FINAL.