You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Qingtian Wang <Qi...@ualloyalty.com> on 2004/07/08 02:26:55 UTC

poi newbie question

Hi,

I am using POI to parse Excel files uploaded from a JSP (jdk1.4, j2ee1.3, weblogic8.1).

At times I can successfully parse the Excel file uploaded, but other times I've got the following error. I am using commons-fileupload to load the Excel file onto the server; and since I don't see any exceptions thrown by that package, I guess the problem happens when I am using POI. (Couldn't figure out why I got the "org.apache.poi.hssf.record.RecordFormatException" exception.)

I am using the HSSFWorkbook() constructor that takes an InputStream as the argument. After getting the workbook, I am pretty much looping over the entire Excel file and printing out the cell values, similar to the sample code that comes with the POI jar (org.apache.poi.hssf.dev.HSSF.java).

Can someone please help?

Thanks very much,
Q. Wang


~~~~~~~

<Jul 7, 2004 5:27:59 PM CDT> <Warning> <HTTP> <BEA-101138> <ServletContext(id=9039851,name=telescope,context-path=/telescope) One of the getParameter family of methods called after reading from the ServletInputStream. Not merging post parameters.> 
[WARNING] Unknown Ptg 3c (60) java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
        at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
        at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:165)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:212)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:193)
        at com.united.telescope.prototype.Excel.<init>(Unknown Source)
        at jsp_servlet._test.__exceldisplay._jspService(__exceldisplay.java:136)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
        at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
        at com.united.telescope.prototype.ExcelReader.processRequest(Unknown Source)
        at com.united.telescope.prototype.ExcelReader.doPost(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
        at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
        at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Caused by: java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
        at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
        at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
        at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
        at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
        at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
        ... 31 more
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance, the following exception occured: null
        at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:237)
        at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:165)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:212)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:193)
        at com.united.telescope.prototype.Excel.<init>(Unknown Source)
        at jsp_servlet._test.__exceldisplay._jspService(__exceldisplay.java:136)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
        at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
        at com.united.telescope.prototype.ExcelReader.processRequest(Unknown Source)
        at com.united.telescope.prototype.ExcelReader.doPost(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
        at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
        at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

~~~~~~~

Re: poi newbie question

Posted by Danny Mui <da...@muibros.com>.
Does this happen when you load the workbook directly (not from file upload)?

What version of HSSF are you using?

Qingtian Wang wrote:

> Hi,
> 
> I am using POI to parse Excel files uploaded from a JSP (jdk1.4, j2ee1.3, weblogic8.1).
> 
> At times I can successfully parse the Excel file uploaded, but other times I've got the following error. I am using commons-fileupload to load the Excel file onto the server; and since I don't see any exceptions thrown by that package, I guess the problem happens when I am using POI. (Couldn't figure out why I got the "org.apache.poi.hssf.record.RecordFormatException" exception.)
> 
> I am using the HSSFWorkbook() constructor that takes an InputStream as the argument. After getting the workbook, I am pretty much looping over the entire Excel file and printing out the cell values, similar to the sample code that comes with the POI jar (org.apache.poi.hssf.dev.HSSF.java).
> 
> Can someone please help?
> 
> Thanks very much,
> Q. Wang
> 
> 
> ~~~~~~~
> 
> <Jul 7, 2004 5:27:59 PM CDT> <Warning> <HTTP> <BEA-101138> <ServletContext(id=9039851,name=telescope,context-path=/telescope) One of the getParameter family of methods called after reading from the ServletInputStream. Not merging post parameters.> 
> [WARNING] Unknown Ptg 3c (60) java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
>         at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
>         at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:165)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:212)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:193)
>         at com.united.telescope.prototype.Excel.<init>(Unknown Source)
>         at jsp_servlet._test.__exceldisplay._jspService(__exceldisplay.java:136)
>         at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
>         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
>         at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
>         at com.united.telescope.prototype.ExcelReader.processRequest(Unknown Source)
>         at com.united.telescope.prototype.ExcelReader.doPost(Unknown Source)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
>         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
>         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
>         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
>         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
>         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
>         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
>         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
> Caused by: java.lang.ArrayIndexOutOfBoundsException
>         at java.lang.System.arraycopy(Native Method)
>         at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
>         at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
>         at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
>         at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
>         at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
>         at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
>         ... 31 more
> org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance, the following exception occured: null
>         at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:237)
>         at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:165)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:212)
>         at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:193)
>         at com.united.telescope.prototype.Excel.<init>(Unknown Source)
>         at jsp_servlet._test.__exceldisplay._jspService(__exceldisplay.java:136)
>         at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
>         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
>         at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
>         at com.united.telescope.prototype.ExcelReader.processRequest(Unknown Source)
>         at com.united.telescope.prototype.ExcelReader.doPost(Unknown Source)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
>         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
>         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
>         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
>         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
>         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
>         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
>         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
>         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
> 
> ~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


null row problem when adding new row

Posted by Naga Raju Parsa <np...@yahoo.com>.
Hi,

 

I'm having the following weird problem.  Can anyone help me please?

 

I've 10 rows in my xls.

 

I add new rows programmatically using the following little add new row method that I wrote.

 

Say, I added one new row after the second row.

If I say, sh.getRow(9), I get the 9th row, which is correct because, there is a new row added.

 

When I try to read the 10th row ( HSSFRow row = sh.getRow(9); ), here the row is null.  Any help is appreciated please.

 

    /**
     * inserts a new row in the spreadsheet
     * @param sh
     * @param newRowNumber
     */
    public static final HSSFRow addNewRow(HSSFSheet sh, int newRowNumber)
    {
        // shift the cells down and make room to add new row
        sh.shiftRows(newRowNumber, sh.getLastRowNum(), 1);

 

        HSSFRow newRow = sh.createRow(newRowNumber);
        HSSFCell         c      = null;

 

        for (short cellnum = ( short ) 0; cellnum < 25; cellnum++) {
            c = newRow.createCell(cellnum, HSSFCell.CELL_TYPE_STRING);
            c.setCellValue("");
        }

 

        return newRow;
    }

 

Thanks in advance,

Naga

 

		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!

Re: out of memory problem when reading xls

Posted by Qingtian Wang <qi...@ualloyalty.com>.
I've read files larger than that without problems. Are you running 
IntelliJ on Windows? What's your virtual memory size? When Java says 
"out of memory", from the system monitor of Windows, do you really see 
all the vitual memory being used up?

Qingtian Wang



Naga Raju Parsa wrote:

> Hi,
>  
> I'm trying to read an xls file which is 2.5 MB, and I get the following exception.
>  
> java.lang.OutOfMemoryError
>  <<no stack trace available>>
> Exception in thread "main" Process terminated with exit code 1
>  
> Here is the code :
>  InputStream myxls = new FileInputStream(exitingXLS1FileName);
>   HSSFWorkbook wbexisting     = new HSSFWorkbook(myxls);
>  
> If I read small size files, it works fine.  Any help is appreciated.
> Running the app (stanalone) under ItelliJ IDEA.
>  
> Thanks,
> Naga Parsa
>  
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> New and Improved Yahoo! Mail - 100MB free storage!

-- 
Qingtian Wang
WHQUL
847-466-9568 (work)
702-447-7688 (fax)

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


out of memory problem when reading xls

Posted by Naga Raju Parsa <np...@yahoo.com>.
Hi,
 
I'm trying to read an xls file which is 2.5 MB, and I get the following exception.
 
java.lang.OutOfMemoryError
 <<no stack trace available>>
Exception in thread "main" Process terminated with exit code 1
 
Here is the code :
 InputStream myxls = new FileInputStream(exitingXLS1FileName);
  HSSFWorkbook wbexisting     = new HSSFWorkbook(myxls);
 
If I read small size files, it works fine.  Any help is appreciated.
Running the app (stanalone) under ItelliJ IDEA.
 
Thanks,
Naga Parsa
 

		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!