You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Dobson, Paul L CTR USAF AFMC 416 SCMS/OBN" <Pa...@HILL.af.mil> on 2009/03/03 20:30:44 UTC
XSSFWorkbook locks file, unable to unlock
I am trying to read an excel 2007 document, modify it, and write it back
out to the same file. When I instantiate XSSFWorkbook, the operating
system (windows XP) will not allow me to change the file until the java
program closes. I've tried everything I can think of to get the file to
release. The lock even exists long after my XSSFWorkbook object is out
of scope.
What I am trying to do is simple.
String masterpath = "some valid path on my C drive";
XSSFWorkbook wb = new XSSFWorkbook(masterPath);
--change a few cell values
wb.write(out); //Fails because the file is locked.
Any ideas?
Re: XSSFWorkbook locks file, unable to unlock
Posted by Yegor Kozlov <ye...@dinom.ru>.
Which version of POI? Can you post the stack trace? Is the file opened
by Excel while the Java program is running?
The following code works fine with current trunk:
String masterPath = "D:\\temp\\original.xlsx";
XSSFWorkbook wb = new XSSFWorkbook(masterPath);
wb.getSheetAt(0).getRow(0).getCell(0).setCellValue("xxx");
FileOutputStream out = new FileOutputStream(masterPath);
wb.write(out);
out.close();
Yegor
> Sorry. I missed a line in the code. The last 2 lines are:
>
> FileOutputStream out = new FileOutputStream(masterPath);
> wb.write(out); //Fails because the file is locked.
>
>
> I am trying to read an excel 2007 document, modify it, and write it back
> out to the same file. When I instantiate XSSFWorkbook, the operating
> system (windows XP) will not allow me to change the file until the java
> program closes. I've tried everything I can think of to get the file to
> release. The lock even exists long after my XSSFWorkbook object is out
> of scope.
>
>
>
> What I am trying to do is simple.
>
>
>
> String masterpath = "some valid path on my C drive";
>
> XSSFWorkbook wb = new XSSFWorkbook(masterPath);
>
> --change a few cell values
>
> wb.write(out); //Fails because the file is locked.
>
>
>
>
>
> Any ideas?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: XSSFWorkbook locks file, unable to unlock
Posted by "Dobson, Paul L CTR USAF AFMC 416 SCMS/OBN" <Pa...@HILL.af.mil>.
Sorry. I missed a line in the code. The last 2 lines are:
FileOutputStream out = new FileOutputStream(masterPath);
wb.write(out); //Fails because the file is locked.
I am trying to read an excel 2007 document, modify it, and write it back
out to the same file. When I instantiate XSSFWorkbook, the operating
system (windows XP) will not allow me to change the file until the java
program closes. I've tried everything I can think of to get the file to
release. The lock even exists long after my XSSFWorkbook object is out
of scope.
What I am trying to do is simple.
String masterpath = "some valid path on my C drive";
XSSFWorkbook wb = new XSSFWorkbook(masterPath);
--change a few cell values
wb.write(out); //Fails because the file is locked.
Any ideas?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org