0

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
  • AFAIK Apache POI supports changing Excel files as well as reading, so where is your problem?
    – Doc Brown
    Commented Aug 19, 2013 at 11:10
  • right now i've to first open a file then read cells then creat another workbook, copy data from first file to that workbook then write 2nd workbook into the first one.... (is this an efficient way..??? I don't think so) Commented Aug 19, 2013 at 11:28
  • 2
    This question appears to be off-topic because it is about an implementation issue with Apache POI.
    – user53019
    Commented Aug 19, 2013 at 12:28

2 Answers 2

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:

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
  • Thanks for response Spoike but i don't want to creat extra workbooks i just want to open one show that one to the user and let the user to change it. just like we did in Ms Excel. Commented Aug 19, 2013 at 11:30
  • @haseebAkhtar Wouldn't it be better to open the file in Excel from your Java program?
    – Spoike
    Commented Aug 19, 2013 at 11:34
  • could you explain please....? (Help me how) Commented Aug 19, 2013 at 11:39
  • @haseebAkhtar You can use Desktop to open files with appropriate program. I.e. it assumes that Excel is installed in the user's computer and that the extension is correctly associated with Excel.
    – Spoike
    Commented Aug 19, 2013 at 11:54
  • Thats cool, thanks for giving me SucH a HelPfuL information.. :) Commented Aug 19, 2013 at 12:00
0

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
  • This is something \m/ Commented Aug 19, 2013 at 11:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.