在JavaFX中打印,导入和导出TableView中的数据 [英] Printing, Importing and Exporting Data Inside TableView in JavaFX

查看:928
本文介绍了在JavaFX中打印,导入和导出TableView中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在tableView中打印数据,还可以使用.csv文件扩展名导出tableView中的数据,最后导入csv文件并在tableView中显示。请帮帮我们。谢谢。

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.

推荐答案

我找到了在此Oracle线程上将数据导出为CSV的解决方案。基本上,您构建了一个类,它组装数据集中的每个对象并获取它的每个元素并将其转换为csv样式字符串。然后创建一个调用此函数的按钮。

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.

主题: https://forums.oracle。 com / thread / 2397100

导出数据的类:

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

这篇关于在JavaFX中打印,导入和导出TableView中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆