public void exportTable(JTable table, File file) throws IOException {
TableModel model = table.getModel();
FileWriter out = new FileWriter(file);
for(int i=0; i < model.getColumnCount(); i++) {
out.write(model.getColumnName(i) + "/t");
}
out.write("/n");
for(int i=0; i< model.getRowCount(); i++) {
for(int j=0; j < model.getColumnCount(); j++) {
String str = (String)model.getValueAt(i,j);
out.write(str + "/t");
}
out.write("/n");
}
out.close();
}
将JTable导出成xls表格
最新推荐文章于 2020-11-19 14:12:11 发布