Hi,
I need to export the values in the JTable component to be exported to MS - excel. Currently it is successfully exported as text file, but when I open in Ms-Excel, the contents are displayed in single cell. Here is the code I have used :
Code:int state = chooser.showSaveDialog(null); File file = chooser.getSelectedFile(); if (file != null && state == JFileChooser.APPROVE_OPTION) { try { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file,true)); PrintWriter fileWriter = new PrintWriter(bufferedWriter); for(int i=0; i<model.getRowCount(); ++i) { for(int j=0; j<model.getColumnCount(); ++j) { String s = model.getValueAt(i,j).toString(); fileWriter.print(s); } fileWriter.println(""); } fileWriter.close(); JOptionPane.showMessageDialog(null, "Success"); }catch(Exception e) { JOptionPane.showMessageDialog(null, "Failure"); } }




Reply With Quote