I'm trying to export a JTable to a file usable by Microsoft Excel.
Originally, I wrote the data to a text file and set the extension as ".xls"
Of course, this was unprofessional, and Excel went on to complain about the format being out of whack. Rightly so.
Anyway, now I'm trying to export it to an XML table, that way I can open it with Excel. However, when I try to export it with XMLEncoder, exceptions are printed, and when opened in Excel, it does not look or work right. Rather than having the data from the tables, the table contains data about the objects and classes.
Here's my code:
public static void saveToXML(JTable table, File location, String name) throws Exception{
XMLEncoder encoder;
File file = new File(location.getAbsolutePath() + "/" + name + ".xml");
encoder = new XMLEncoder(new FileOutputStream(file));
encoder.writeObject(table);
encoder.close();
}
The exceptions that are printed are as follows:
java.lang.InstantiationException: fbla.evaluation.window.MainWindow$2
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.new();
Continuing ...
java.lang.InstantiationException: javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement JTableHeader.removeMouseMotionListener(BasicTableHeaderUI$MouseInputHandler);
Continuing ...
java.lang.InstantiationException: fbla.evaluation.window.MainWindow$38
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement JTable.addMouseListener(MainWindow$38);
Continuing ...
java.lang.InstantiationException: javax.swing.plaf.basic.BasicTableUI$Handler
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement JTable.removeMouseMotionListener(BasicTableUI$Handler);
Continuing ...
Any help and insight is greatly appreciated. It's probably also worth mentioning that the tables Model is a custom one.