0

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?

1
  • Sorry I wasnt very clear, I guess what I mean is when I run the program and gather information from the user. I want it to permanently save the data to the excel document. As of now it will create the excel document but once I run the program again, the data from the previous run is no longer stored. I want to be able to keep the data from each successive run. Commented Mar 30, 2014 at 21:33

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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();

Comments

0

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

Comments

0

If I got you right, you should end your code with:

FileOutputStream outputStream = new FileOutputStream(excelFilePath);
wb.write(outputStream);
outputStream.close();
inputStream.close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.