You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Natu, Ashlesha [IT]" <as...@citigroup.com> on 2006/03/30 17:17:28 UTC

Exception while reading Excel sheet

Hi,
 
I am new to POI. I am trying to upload an excel sheet and read it using POI. 
My html code is:
<form name="frmNTest" enctype="MULTIPART/FORM-DATA" method="post" action="test.jsp">
<input type=hidden name=hfrmID value="frmTest">
<input type=hidden name=hfrmActionID value="uploadFiletoServer">
<table width="98%" border=0>
<tr>
 <td>Select File</td>
 <td><input type="file" name="updfilename">
 </td>
</tr>
 
<tr>
 <td colspan="2"><div align="center">
 <input type="submit" name=Submit value="Upload">
 </div></td>
</tr>
</table>

**************************
My server side code is: (test.jsp)
<%
UploadFile up = new UploadFile();
up.doUpload(request,response);
%>
********************************
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
import org.apache.poi.hssf.util.*;
import org.apache.poi.hssf.eventmodel.*;
import org.apache.poi.hssf.eventusermodel.*;
import org.apache.poi.hssf.dev.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.FileInputStream;
import java.io.InputStream;

public class UploadFile {
 
public void doUpload(HttpServletRequest request, HttpServletResponse response) throws IOException
{
 try
 { 
  ServletInputStream is = request.getInputStream();
  InputStream ins = (InputStream)is;
  POIFSFileSystem fs = new POIFSFileSystem(ins);
  HSSFWorkbook wb = new HSSFWorkbook(fs);
  HSSFSheet sheet = wb.getSheetAt(0);
  HSSFRow row = sheet.getRow(1);
  HSSFCell cell = row.getCell((short)0);
  String c1 = cell.getStringCellValue();
 }
 catch(IOException io)
 {
  LCMLogger.log("io error = " + io.toString());
 }
}
}
*******************
I am getting the following exception:
java.io.IOException: Invalid header signature; read 3255307777713450285, expected -2226271756974174256
**********************
If I hard copy the filename instead as below, then the code works fine and I can read the cell contents.
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("Test.xls"));
 
Please can anyone help me in this matter? Why doesn't the POIFSFileSystem object get created when I pass an input stream to it? 
 
thanks, AN
 

Re: Exception while reading Excel sheet

Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 8 Jan 2008, teena21 wrote:
> i have the same problem if u got the solution plz tell me

You're sending multi-part data to the server, but not doing a multi-part
aware handling of the request inputstream. So, what you're passing to
POIFSFileSystem isn't the ole2 document, it's still the multipart wrapper.

Check the tutorials of your servlet programming environment for details on
how to unpack the multi-part stread to get just the ole2 document to pass
to poi

Nick

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


Re: Exception while reading Excel sheet

Posted by teena21 <fr...@yahoo.com>.
hi
i have the same problem if u got the solution plz tell me
thanks

Natu, Ashlesha [IT] wrote:
> 
> Hi,
>  
> I am new to POI. I am trying to upload an excel sheet and read it using
> POI. 
> My html code is:
> <form name="frmNTest" enctype="MULTIPART/FORM-DATA" method="post"
> action="test.jsp">
> <input type=hidden name=hfrmID value="frmTest">
> <input type=hidden name=hfrmActionID value="uploadFiletoServer">
> <table width="98%" border=0>
> <tr>
>  <td>Select File</td>
>  <td><input type="file" name="updfilename">
>  </td>
> </tr>
>  
> <tr>
>  <td colspan="2"><div align="center">
>  <input type="submit" name=Submit value="Upload">
>  </div></td>
> </tr>
> </table>
> 
> **************************
> My server side code is: (test.jsp)
> <%
> UploadFile up = new UploadFile();
> up.doUpload(request,response);
> %>
> ********************************
> import java.io.*;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.ServletInputStream;
> import org.apache.poi.hssf.util.*;
> import org.apache.poi.hssf.eventmodel.*;
> import org.apache.poi.hssf.eventusermodel.*;
> import org.apache.poi.hssf.dev.*;
> import org.apache.poi.hssf.usermodel.*;
> import org.apache.poi.poifs.filesystem.*;
> import java.io.FileInputStream;
> import java.io.InputStream;
> 
> public class UploadFile {
>  
> public void doUpload(HttpServletRequest request, HttpServletResponse
> response) throws IOException
> {
>  try
>  { 
>   ServletInputStream is = request.getInputStream();
>   InputStream ins = (InputStream)is;
>   POIFSFileSystem fs = new POIFSFileSystem(ins);
>   HSSFWorkbook wb = new HSSFWorkbook(fs);
>   HSSFSheet sheet = wb.getSheetAt(0);
>   HSSFRow row = sheet.getRow(1);
>   HSSFCell cell = row.getCell((short)0);
>   String c1 = cell.getStringCellValue();
>  }
>  catch(IOException io)
>  {
>   LCMLogger.log("io error = " + io.toString());
>  }
> }
> }
> *******************
> I am getting the following exception:
> java.io.IOException: Invalid header signature; read 3255307777713450285,
> expected -2226271756974174256
> **********************
> If I hard copy the filename instead as below, then the code works fine and
> I can read the cell contents.
> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("Test.xls"));
>  
> Please can anyone help me in this matter? Why doesn't the POIFSFileSystem
> object get created when I pass an input stream to it? 
>  
> thanks, AN
>  
> 
> 

-- 
View this message in context: http://www.nabble.com/Exception-while-reading-Excel-sheet-tp3672134p14689734.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: Exception while reading Excel sheet

Posted by Tom Schindl <to...@gmx.at>.
Well data is sent to you following multipart/form-data you need to use
something like commons-fileupload
(http://jakarta.apache.org/commons/fileupload/) to read the file sent to
you from the browser.

Tom

Natu, Ashlesha [IT] wrote:
> Hi,
>  
> I am new to POI. I am trying to upload an excel sheet and read it using POI. 
> My html code is:
> <form name="frmNTest" enctype="MULTIPART/FORM-DATA" method="post" action="test.jsp">
> <input type=hidden name=hfrmID value="frmTest">
> <input type=hidden name=hfrmActionID value="uploadFiletoServer">
> <table width="98%" border=0>
> <tr>
>  <td>Select File</td>
>  <td><input type="file" name="updfilename">
>  </td>
> </tr>
>  
> <tr>
>  <td colspan="2"><div align="center">
>  <input type="submit" name=Submit value="Upload">
>  </div></td>
> </tr>
> </table>
> 
> **************************
> My server side code is: (test.jsp)
> <%
> UploadFile up = new UploadFile();
> up.doUpload(request,response);
> %>
> ********************************
> import java.io.*;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.ServletInputStream;
> import org.apache.poi.hssf.util.*;
> import org.apache.poi.hssf.eventmodel.*;
> import org.apache.poi.hssf.eventusermodel.*;
> import org.apache.poi.hssf.dev.*;
> import org.apache.poi.hssf.usermodel.*;
> import org.apache.poi.poifs.filesystem.*;
> import java.io.FileInputStream;
> import java.io.InputStream;
> 
> public class UploadFile {
>  
> public void doUpload(HttpServletRequest request, HttpServletResponse response) throws IOException
> {
>  try
>  { 
>   ServletInputStream is = request.getInputStream();
>   InputStream ins = (InputStream)is;
>   POIFSFileSystem fs = new POIFSFileSystem(ins);
>   HSSFWorkbook wb = new HSSFWorkbook(fs);
>   HSSFSheet sheet = wb.getSheetAt(0);
>   HSSFRow row = sheet.getRow(1);
>   HSSFCell cell = row.getCell((short)0);
>   String c1 = cell.getStringCellValue();
>  }
>  catch(IOException io)
>  {
>   LCMLogger.log("io error = " + io.toString());
>  }
> }
> }
> *******************
> I am getting the following exception:
> java.io.IOException: Invalid header signature; read 3255307777713450285, expected -2226271756974174256
> **********************
> If I hard copy the filename instead as below, then the code works fine and I can read the cell contents.
> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("Test.xls"));
>  
> Please can anyone help me in this matter? Why doesn't the POIFSFileSystem object get created when I pass an input stream to it? 
>  
> thanks, AN
>  
>