By no means should I be considered an expert with XSSF - in fact I have only
used this stream once or twice as I do not have Office 2007 on my machine.
Nevertheless, I believe that somewhere along the line, the XSSFWorkbook
class uses a stream to connect to the spreadsheet file in order to read it's
contents. It is likely that the stream is the object that is causing your
file lock. So, if it is possible, pass something like a FileInputStream
object to the XSSFWorkbook constructor. As you have access to the stream
object in your code, all you need to do is call the close method on it to
release the lock on the file; something like this.
FileInputStream fileIStream = new FileInputStream(new
File("................."));
XSSFWorkbook workbook = new XSSFWorkbook(fileIStream);
.........
then when you want to release the file, just call;
fileIStream.close();
Suladna wrote:
>
> Hi!
>
> I'm using the below code to bring text from Excel to Java:
>
> XSSFWorkbook wb = new XSSFWorkbook("C:/myDocument.xlsm");
> XSSFSheet sheet = wb.getSheet("Sheet1");
> Row firstRow = sheet.getRow(0);
> System.out.println(firstRow.getCell(0).getRichStringCellValue().getString())
>
> If I run the above program and terminate it, I am able to save
> myDocument.xlsm. However, if I run the program without terminating it
> (i.e. I let it continue running other code), I am not able to save
> myDocument.xlsm!
>
> If I try doing so, I get an error message telling me that the document
> can't be saved because of a sharing error and that I should try saving it
> to another file. Can anything be done to prevent this error?
>
> Best regards,
> Sul Adna
>
>
>
>
--
View this message in context:
http://www.nabble.com/Unable-to-save-Excel-file-after-having-connected-it-to-Java-tp23134819p23149963.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]