poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xb <a...@hotmail.com>
Subject Re: Workbook multiple write, single outputstream close
Date Sun, 05 Jul 2009 17:54:54 GMT

Thank you Mark for your reply. I was hoping to keep updating the stream. The
file can get pretty big and I don't want to use all the information, in case
of an unexpected program exit.

MSB wrote:
> You should only call the write(OutputStream) method once, when you have
> finished building the workbook and want to write to away. As you have
> found out, whilst no exception will be thrown if you call it multiple
> times, nothing actually happens - by which I mean nothing will be written
> to the saved workbook following the firsat call of the the write() method.
> To be honest, I do not know why this is as the stream remains open, but I
> am going to assume that it has to do with all of the work that goes in to
> preparing the file ready to be written away.
> Whilst the workbook is in memory, there is nothing stopping you from
> modifying the value in a cell so it may well be that you do not have to
> write the workbook away multiple times. Your original code snippet could
> be re-written as;
> cell.setCellValue(1.5);
> ......
> cell.setCellValue(3.5);
> workbook.write(outputstream);
> ......
> outputstream.close();
> Each call to the setCellValue() method will update the 'in memory' version
> of the workbook.
> Yours
> Mark B
> Xb wrote:
>> Hello everyone,
>> I'm relatively new to POI, but I have some experience with Interop in C#.
>> I need to update an open xls file multiple times and I'm doing so with
>> the method workbook.write(outputstream). I don't close the stream after
>> each write since that would force a reopening of the stream. The problem
>> is that only the first write is visible in the file although the file
>> size seems to indicate that all the data is present. At the end of the
>> main method I close the stream. If I write the workbook at the end, then
>> I can see all the data in the file.
>> Allow me to give you an example:
>> cell.setCellValue(1.5);
>> workbook.write(outputstream);
>> ......
>> cell.setCellValue(3.5);
>> workbook.write(outputstream);
>> ......
>> outputstream.close();
>> Only the value 1.5 exists in the xls file.
>> Thanks in advance for any input.

View this message in context: http://www.nabble.com/Workbook-multiple-write%2C-single-outputstream-close-tp24337575p24345327.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

View raw message