30/09/2018, 18:23
How to Write a jtable with vietnameses in java
Here is my code to write my Jtable to excel. Its working but with error. Something was wrong with charater vietnameses
What should i do?
JFileChooser chooser = new JFileChooser();
int i = chooser.showSaveDialog(this);
if (i == JFileChooser.APPROVE_OPTION) {
FileWriter out = null;
try {
File file = chooser.getSelectedFile();
out = new FileWriter(file + ".xls");
BufferedWriter bwrWriter = new BufferedWriter(out);
DefaultTableModel model = (DefaultTableModel)tblSell2.getModel();
for(int j =0 ; j <model.getColumnCount(); j++) {
bwrWriter.write(model.getColumnName(j) + " ");
}
bwrWriter.write("
");
for(int j = 0; j <model.getRowCount(); j++) {
for(int k = 0; k<model.getColumnCount(); k++) {
bwrWriter.write(model.getValueAt(j, k) + " ");
}
bwrWriter.write("
");
}
bwrWriter.close();
JOptionPane.showMessageDialog(this, "Saved");
} catch (IOException ex) {
Logger.getLogger(JPSell.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
try {
out.close();
} catch (IOException ex) {
Logger.getLogger(JPSell.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Bài liên quan