Swing的JTable导出excel

public void exportTable(JTable table, File file) throws IOException {
TableModel model = table.getModel();//得到Jtable的Model
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++) {
//	if(model.getValueAt(i,j).toString()!=null&&!model.getValueAt(i,j).toString().equals(""))
//	{
//		out.write(model.getValueAt(i,j).toString()+"\t");
//	}else{
//		out.write("null"+"\t");
//	}
	out.write(model.getValueAt(i,j).toString()+"\t");
}
out.write("\n");
}
out.close();
System.out.println("write out to: " + file);
}

 

你可能感兴趣的:(swing,导出Excel,Jtable导出excel)