Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Extract JTable to Microsoft Excel(Eclipse Java - Extract to Excel)
Extract JTable to Microsoft Excel [message #1800536] Tue, 01 January 2019 18:58
John Browning is currently offline John BrowningFriend
Messages: 1
Registered: January 2019
Junior Member

First, i must admit that i'm new to Java world. So a beginner.
I'm trying to extract data from my JTable to Microsoft excel using below code.
The problem is that i don't have any errors but it does not export anything.
Would you be able to help me?

Thank you

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class test_no_1 {
         * Launch the application.
	public static void main(String[] args) {
        String[][] data = {{"Desks", "Rs.1275.00"},
                {"Tools", "Rs.125.00"}, {"Electronics", "Rs.2533.00"},
                {"Woods", "Rs.497.00"}
            String[] headers = {"Departement", "Revenue"};
            JFrame frame = new JFrame("JTable to Excel");
            DefaultTableModel model = new DefaultTableModel(data, headers);
            final JTable table = new JTable(model);
            JScrollPane scroll = new JScrollPane(table);
            JButton export = new JButton("Export");
            export.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    try {
                        ExcelExporter exp = new ExcelExporter();
                        exp.fillData(table, new File("C:\\result.xls"));
                        JOptionPane.showMessageDialog(null, "Data saved to " +
                                "'C:\\result.xls'  correctly", "Message",
                    } catch (Exception ex) {
            frame.getContentPane().add("Center", scroll);
            frame.getContentPane().add("South", export);
         //   frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

I'm under Eclipse version: 2018-09(4.9.0)
Previous Topic:Paths with imbedded spaces
Next Topic:How to remove ANT Configurations?
Goto Forum:

Current Time: Fri Jul 01 06:04:14 GMT 2022

Powered by FUDForum. Page generated in 0.01926 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top