You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Sanabria, Javier (GE Energy, Non GE)" <ja...@ps.ge.com> on 2004/10/12 20:14:56 UTC

Error using HSSF with excel

Hi, I have a problem using POI with a excel file.

I start making a file copy and creating the POIFSFileSystem for the OUT
File.

	String slINPathName = AORConstants.getFolderPath() +
AORConstants.getExcelEmptyTemplName();
	String slOUTPathName = AORConstants.getFolderPath() + "Work file " +
                    	    AORConstants.getExcelFileUrl();

	copyFiles(slINPathName, slOUTPathName);

	POIFSFileSystem objlPOIFileSys = 
		new POIFSFileSystem(new FileInputStream(slOUTPathName));

Next, I create the HSSFWorkbook object and get a sheet of it:

	HSSFWorkbook objlHSSFWb = new HSSFWorkbook(objlPOIFileSys);
	HSSFSheet objlHSSFSheet = objlHSSFWb.getSheet("Input");

Next, I get a particular row and cell and set a new value:

	HSSFRow objlHSSFRow = objlHSSFSheet.getRow(1);
      HSSFCell objlHSSFCell = objlHSSFRow.getCell(2);
	objlHSSFCell.setCellValue("PPP1");

and finally write the book:

	FileOutputStream objlfileOut = new FileOutputStream(slOUTPathName);
      objaHSSFWb.write(objlfileOut);
      objlfileOut.close(); 
	objlfileOut = null;

The original file's size is: 1775KB but, after write, the file's size is
2292KB and when I try open it I got : "File error: data may have been lost"
and my excel breaks.

What do am I doing wrong ???

Thanks for your help.

Notes:
- This is happenin with POI 2.5.1 and 1.5.1
- If you need the complete java source and the excel file for tests I can
provide you.

Thanks again

Javier Perez Sanabria
	


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


Re: Error using HSSF with excel

Posted by Steve <st...@Basit.COM>.
could the problem be that you're not closing the output stream, in
copyFiles(...)  ??

----- Original Message ----- 
From: "Danny Mui" <da...@muibros.com>
To: "POI Users List" <po...@jakarta.apache.org>
Sent: Tuesday, October 12, 2004 7:11 PM
Subject: Re: Error using HSSF with excel


> are you using anything fancy in the sheet?
>
> user forms? graphs?
>
> try to isolate the problem so it's more manageable, i'm not looking
> through 1775/2292 kb or records :)
>
> Sanabria, Javier (GE Energy, Non GE) wrote:
> > Hi, I have a problem using POI with a excel file.
> >
> > I start making a file copy and creating the POIFSFileSystem for the OUT
> > File.
> >
> > String slINPathName = AORConstants.getFolderPath() +
> > AORConstants.getExcelEmptyTemplName();
> > String slOUTPathName = AORConstants.getFolderPath() + "Work file " +
> >                         AORConstants.getExcelFileUrl();
> >
> > copyFiles(slINPathName, slOUTPathName);
> >
> > POIFSFileSystem objlPOIFileSys =
> > new POIFSFileSystem(new FileInputStream(slOUTPathName));
> >
> > Next, I create the HSSFWorkbook object and get a sheet of it:
> >
> > HSSFWorkbook objlHSSFWb = new HSSFWorkbook(objlPOIFileSys);
> > HSSFSheet objlHSSFSheet = objlHSSFWb.getSheet("Input");
> >
> > Next, I get a particular row and cell and set a new value:
> >
> > HSSFRow objlHSSFRow = objlHSSFSheet.getRow(1);
> >       HSSFCell objlHSSFCell = objlHSSFRow.getCell(2);
> > objlHSSFCell.setCellValue("PPP1");
> >
> > and finally write the book:
> >
> > FileOutputStream objlfileOut = new FileOutputStream(slOUTPathName);
> >       objaHSSFWb.write(objlfileOut);
> >       objlfileOut.close();
> > objlfileOut = null;
> >
> > The original file's size is: 1775KB but, after write, the file's size is
> > 2292KB and when I try open it I got : "File error: data may have been
lost"
> > and my excel breaks.
> >
> > What do am I doing wrong ???
> >
> > Thanks for your help.
> >
> > Notes:
> > - This is happenin with POI 2.5.1 and 1.5.1
> > - If you need the complete java source and the excel file for tests I
can
> > provide you.
> >
> > Thanks again
> >
> > Javier Perez Sanabria
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>


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


Re: Error using HSSF with excel

Posted by Danny Mui <da...@muibros.com>.
are you using anything fancy in the sheet?

user forms? graphs?

try to isolate the problem so it's more manageable, i'm not looking 
through 1775/2292 kb or records :)

Sanabria, Javier (GE Energy, Non GE) wrote:
> Hi, I have a problem using POI with a excel file.
> 
> I start making a file copy and creating the POIFSFileSystem for the OUT
> File.
> 
> 	String slINPathName = AORConstants.getFolderPath() +
> AORConstants.getExcelEmptyTemplName();
> 	String slOUTPathName = AORConstants.getFolderPath() + "Work file " +
>                     	    AORConstants.getExcelFileUrl();
> 
> 	copyFiles(slINPathName, slOUTPathName);
> 
> 	POIFSFileSystem objlPOIFileSys = 
> 		new POIFSFileSystem(new FileInputStream(slOUTPathName));
> 
> Next, I create the HSSFWorkbook object and get a sheet of it:
> 
> 	HSSFWorkbook objlHSSFWb = new HSSFWorkbook(objlPOIFileSys);
> 	HSSFSheet objlHSSFSheet = objlHSSFWb.getSheet("Input");
> 
> Next, I get a particular row and cell and set a new value:
> 
> 	HSSFRow objlHSSFRow = objlHSSFSheet.getRow(1);
>       HSSFCell objlHSSFCell = objlHSSFRow.getCell(2);
> 	objlHSSFCell.setCellValue("PPP1");
> 
> and finally write the book:
> 
> 	FileOutputStream objlfileOut = new FileOutputStream(slOUTPathName);
>       objaHSSFWb.write(objlfileOut);
>       objlfileOut.close(); 
> 	objlfileOut = null;
> 
> The original file's size is: 1775KB but, after write, the file's size is
> 2292KB and when I try open it I got : "File error: data may have been lost"
> and my excel breaks.
> 
> What do am I doing wrong ???
> 
> Thanks for your help.
> 
> Notes:
> - This is happenin with POI 2.5.1 and 1.5.1
> - If you need the complete java source and the excel file for tests I can
> provide you.
> 
> Thanks again
> 
> Javier Perez Sanabria
> 	
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org

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