Printing, Importing and Exporting Data Inside TableView in JavaFX


Question

Is there a way on how to print data inside the tableView and also to export the data in the tableView with ".csv" file extension and lastly to import the csv file and display inside the tableView. Please help me guys. Thanks.

1
2
6/30/2015 1:21:38 AM

I found the solution for exporting data to CSV on this Oracle Thread. Basically you build a class that assembles each object in your dataset and takes each element of it and turn that into a csv style string. Then you create a button that calls this function.

Thread: https://forums.oracle.com/thread/2397100

class for exporting data:

public void writeExcel() throws Exception {
    Writer writer = null;
    try {
        File file = new File("C:\\Person.csv.");
        writer = new BufferedWriter(new FileWriter(file));
        for (Person person : data) {

            String text = person.getFirstName() + "," + person.getLastName() + "," + person.getEmail() + "\n";



            writer.write(text);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    finally {

        writer.flush();
         writer.close();
    } 
}
2
9/8/2013 2:34:35 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon