[英]Export jTable selection to excel and open excel
I have a jtable with lots of records;I need to select some of the records in the jTable and output it to excel along with the jTable Header of selected columns.The excel should open automatically with the selected data on exporting.
谢谢你
您可以使用以下代码从 JTable 创建文件
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file,true));
PrintWriter fileWriter = new PrintWriter(bufferedWriter);
for(int i=0; i<model.getRowCount(); ++i)
{
for(int j=0; j<model.getColumnCount(); ++j)
{
String s = model.getValueAt(i,j).toString();
fileWriter.print(s + ",");
}
fileWriter.println("\n");
}
fileWriter.close();
这段代码正在做的是创建一个 CSV 文件,您需要了解如何创建文件以及什么是 csv 文件以及如何打开它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.