0

I am able to read in and edit values of a spreadsheet that is already saved in the correct location for eclipse.

However I'd like the user to be able to click a button on the front end of my application and then be able to search for a valid excel file stored on their computer which they can then import into the application so that my application perform operations on the data. Similarly I'd like them to be able to export an excel spreadsheet template from my application.

JTable only seems to be for displaying data in a table format not actually importing/exporting.

Is this possible with Swing and how do you do it? If this is asking too much of Swing are there any other UI toolkits that would also me to do this? (I am at the early stages of front end development and can still change)

user2989759
  • 279
  • 1
  • 4
  • 14
  • 1
    Well i think there is nothing built in, but if you search in google you can find something, you would have to use a JFileChooser to import excel to your application, use some parser like `Apache POI` and then create your `TableModel` based on that data to show in view(JTable) Here is a related [question](http://stackoverflow.com/questions/7306661/importing-excel-xls-in-java-swing) – nachokk Dec 30 '13 at 13:53

1 Answers1

2

For import, I use Apache , seen here, in an AbstractTableModel, illustrated here. For export, you may be able to leverage the Drag & Drop approach shown here.

Addendum: What I'd like is for the user to somehow be able to explore their directory and choose their own [File].

Pass the chosen File as a constructor parameter to your TableModel and use setModel() to update the table in place. As shown here, updating the table model will update the listening table view automatically.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I am using Apache POI to read in a File at the moment but the value of the Fail is just a String that I have hardcoded into the parameter. What I'd like is for the user to somehow be able to explore their directory and choose their own instead of this. – user2989759 Dec 30 '13 at 14:28
  • Sounds reasonable; I've elaborated above. – trashgod Dec 30 '13 at 16:18