I’ve made a file browser in java that opens and read already been made excel files. (using Apache poi 3.9 library)
program read those files perfectly but i want to update some of those files. how can i be able to update those files through my program.
is there is any library or function/class that might be helpful, or also any other language that can support that feature (among c/c++, python)..???
3
There are a bunch of examples on the Apachi POI library site on how to change and save Excel files. Here are a couple of pages to get you started:
- Apache POI Spreadsheet HOWTO – The New Halloween Document
- Apache POI Spreadsheet Quick Guide – Busy Developers’ Guide to HSSF and XSSF Features
E.g. workbook objects in the library have a write(…)
method if you want to save the contents of it to a file using an appropriate OutputStream
:
// Save a workbook (wb)
FileOutputStream out = new FileOutputStream("my_workbook.xls");
wb.write(out);
out.close();
If you want to open the files in Excel you can, according to this answer, try using Desktop
which is available in JDK6.
Desktop.getDesktop().open(new File("c:\file.xls"));
5
If POI is not sufficient for any kind of reasons, you may have to utilize Excel by using COM Automation for such a task. Read this SO post for more information how to do this in Java. But beware, this will have some drawbacks:
- platform-dependent (will only work on Windows)
- won’t work well for a server-side application
- slow (compared to direct access by POI)
1