Reputation: 1
I feel dumb asking this, but right now I'm using Apache POI to write to an Excel document. But as of right now, every time I run the program it doesn't save the data to the excel document, meaning the next time I run it the data from previous trails isn't there. Is there a line of code for saving all the info gathered during a trial so that it is still there in future trials?
Upvotes: 0
Views: 4144
Reputation: 81
If I got you right, you should end your code with:
FileOutputStream outputStream = new FileOutputStream(excelFilePath);
wb.write(outputStream);
outputStream.close();
inputStream.close();
Upvotes: 0
Reputation: 11132
As Paul mentioned, you need workbook.write()
,
here's usage:
HSSFWorkbook workbook = new HSSFWorkbook();
.......
FileOutputStream out = new FileOutputStream(new File("D:\\file.xls"));
workbook.write(out);
out.close();
Upvotes: 1
Reputation: 822
There is an example on the JED website you might want to check out which demonstrates how to collect data from an HTML table and save it to an Excel file using the POI library. You should get all you need in the way of servlet code to replicate for your purposes.
Try: http://jed-datatables.ca/jed/examples/exporttoexcel2.html
Upvotes: 0
Reputation: 41769
Assuming you're trying to save the created workbook to the file system, I think you want Workbook.write and one of the constructors for the spreadsheet format you use to read it in again (e.g. XSSFWorkbook(java.io.InputStream from here)
write
void write(java.io.OutputStream stream) java.io.IOException
Write out this workbook to an Outputstream.
Parameters:
stream - - the java OutputStream you> wish to write to
Throws: java.io.IOException - if anything can't> be written.
Upvotes: 2