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 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public class JExporter {
public void exporter(JTable table, File file)
{
try
{
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++) {
Object value=model.getValueAt(i,j)+"\t";
if ( value!=null ){
out.write(value.toString()+"\t");
}
else{ out.write(" ");
}
out.write("\n");
}
}
out.close();
} catch(Exception err)
{
err.printStackTrace();
}
}
} |
Partager