1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class ExcelExporter {
ExcelExporter(){}
public void exportTable (JTable table,File file) throws IOException {
TableModel model = table.getModel();
FileWriter out = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(out);
for(int i=0;i<model.getColumnCount();i++)
{
bw.write(model.getColumnName(i)+"\t");
}
bw.write("\n");
for(int i=0;i<model.getRowCount();i++)
{
for (int j=0;j<model.getColumnCount();j++)
{
bw.write(model.getValueAt(i,j).toString()+"\t");
}
bw.write("\n");
}
bw.close();
System.out.print("Write out to"+file);
}
} |
Partager