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-tp24337575p24344515.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]
