I have a quick question. I made program which generates jtable, than you can fill this table with some values, and than save whole table to excel.
At the begging beginning I defined file:
File f = new File("C:\Users\Gregory\Desktop\test.xls");
Here is class which export JTable to excel:
public void exportTable(JTable table, File file) throws IOException { TableModel model = table.getModel(); FileWriter out = new FileWriter(file);
for (int i = 0; i < model.getColumnCount(); i++) { out.write(table.getColumnModel().getColumn(i).getHeaderValue() + \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) != null) { out.write(model.getValueAt(i, j).toString() + "\t"); } else if (model.getValueAt(i, j) == null) { out.write("\t"); } } out.write("\n"); }out.close();
I cannot import this table to java program. I receive the error: jxl.read.biff.BiffException: Unable to recognize OLE stream
When I open this file I have message, that the format of the file is different than its extension (.xls). So I click "save as" and suggested extension is .txt. I save file as .xls (seems to be the same file as saved by java program) and than I can import JTable from that excel to java program without any errors. Can anyone suggest how to save file with right extension?