22 thoughts on “How to Generate Excel in Java and Write data

  1. Based on its homepage it seems that "jxl.jar" supports only up to 2003 workbooks, is that right?

    Anyway, a different approach that you can use to create an Excel file (even the latest XLSX from MS Excel 2019) is with "gembox-spreadsheet.jar" from:

    https://www.gemboxsoftware.com/spreadsheet-java

    For example like this:

    ExcelFile myexcel = new ExcelFile();

    ExcelWorksheet mysheet = workbook.addWorksheet("mySheet");

    worksheet.getCell("A1").setValue("data 1");

    worksheet.getCell(0, 1).setValue("data 2");

    myexcel.save("C:\Users\FE.86400\Desktop\exe1.xlsx");

    You can find another writing example on:

    https://www.gemboxsoftware.com/spreadsheet-java/examples/create-write-excel-file-in-java/402

  2. package exceluserform;

    import java.util.*;
    import java.awt.Color;

    import java.awt.EventQueue;
    import java.awt.Font;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;

    import jxl.Sheet;
    import jxl.Workbook;

    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.awt.event.ActionEvent;
    public class filename {

    private String id;
    private String name;
    private long price;
    private int quantity;
    private Date creationDate;

    JFrame frame;
    private JTextField txtCuserforms;

    /**
    * Launch the application.
    */

    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    filename window = new filename();
    window.frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the application.
    */
    public filename() {
    initialize();
    }

    /**
    * Initialize the contents of the frame.
    */
    private void initialize() {

    frame = new JFrame();
    frame.setBackground(Color.BLACK);
    frame.getContentPane().setBackground(Color.WHITE);
    frame.getContentPane().setLayout(null);
    frame.setBounds(100, 100, 609, 391);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel lblWelcome = new JLabel(" plaease choose your file's ");
    lblWelcome.setFont(new Font("Tahoma", Font.BOLD, 23));
    lblWelcome.setBounds(40, 4, 543, 73);
    frame.getContentPane().add(lblWelcome);

    txtCuserforms = new JTextField();
    txtCuserforms.setText("C:\USERFORMS\.xls");
    txtCuserforms.setHorizontalAlignment(SwingConstants.CENTER);
    txtCuserforms.setBackground(Color.WHITE);
    txtCuserforms.setFont(new Font("Tahoma", Font.BOLD, 15));
    txtCuserforms.setBounds(125, 88, 302, 89);
    frame.getContentPane().add(txtCuserforms);
    txtCuserforms.setColumns(10);

    JButton btnNewButton = new JButton("CREATE FILE");
    btnNewButton.setBackground(Color.WHITE);
    btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 18));
    btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    exceluserforma window = new exceluserforma();
    window.frame.setVisible(true);
    } catch (Exception e1) {
    e1.printStackTrace();

    }

    btnNewButton_FileActionPerformed(e);
    }

    private void btnNewButton_FileActionPerformed(ActionEvent e) {

    File f = new File(txtCuserforms.getText());
    if(!f.exists())
    {
    try {
    f.createNewFile();
    f.mkdir();
    JOptionPane.showMessageDialog(null, "File Created");
    PrintWriter pw = new PrintWriter(f);

    } catch (IOException ex) {
    Logger.getLogger(filename.class.getName()).log(Level.SEVERE, null, ex);
    }
    }else{
    JOptionPane.showMessageDialog(null, "File Already Exists");
    }

    }
    });
    btnNewButton.setBounds(170, 227, 234, 60);
    frame.getContentPane().add(btnNewButton);

    }

    }
    package exceluserform;

    import javax.swing.JFrame;

    import java.awt.EventQueue;

    import javax.swing.JFrame;

    import java.awt.Desktop;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JTextArea;

    import jxl.Workbook;
    import jxl.write.WritableCell;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;

    import javax.swing.JLabel;
    import javax.swing.JOptionPane;

    import java.awt.Font;
    import java.awt.Label;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.awt.event.ActionEvent;
    import java.awt.Color;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    public class welcoma<using> {
    using System,IO;
    JFrame frame;

    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    welcoma window = new welcoma();
    window.frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the application.
    */
    public welcoma() {
    initialize();
    }

    /**
    * Initialize the contents of the frame.
    */
    private void initialize() {
    frame = new JFrame();
    frame.setBackground(Color.BLACK);
    frame.getContentPane().setForeground(Color.WHITE);
    frame.getContentPane().setBackground(new Color(240, 240, 240));
    frame.setBounds(100, 100, 609, 391);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("GENERATE AND WORK");
    btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    filename window1 = new filename();
    window1.frame.setVisible(true);
    } catch (Exception e1) {
    e1.printStackTrace();
    }
    frame.dispose(); //close current frame

    }
    });package exceluserform;

    import javax.swing.JFrame;

    import java.awt.EventQueue;

    import javax.swing.JFrame;

    import java.awt.Desktop;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JTextArea;

    import jxl.Workbook;
    import jxl.write.WritableCell;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;

    import javax.swing.JLabel;
    import javax.swing.JOptionPane;

    import java.awt.Font;
    import java.awt.Label;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.awt.event.ActionEvent;
    import java.awt.Color;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    public class welcoma<using> {
    using System,IO;
    JFrame frame;

    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    welcoma window = new welcoma();
    window.frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the application.
    */
    public welcoma() {
    initialize();
    }

    /**
    * Initialize the contents of the frame.
    */
    private void initialize() {
    frame = new JFrame();
    frame.setBackground(Color.BLACK);
    frame.getContentPane().setForeground(Color.WHITE);
    frame.getContentPane().setBackground(new Color(240, 240, 240));
    frame.setBounds(100, 100, 609, 391);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("GENERATE AND WORK");
    btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    filename window1 = new filename();
    window1.frame.setVisible(true);
    } catch (Exception e1) {
    e1.printStackTrace();
    }
    frame.dispose(); //close current frame

    }
    });package exceluserform;

    import javax.swing.JFrame;

    import java.awt.EventQueue;

    import javax.swing.JFrame;

    import java.awt.Desktop;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JTextArea;

    import jxl.Workbook;
    import jxl.write.WritableCell;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;

    import javax.swing.JLabel;
    import javax.swing.JOptionPane;

    import java.awt.Font;
    import java.awt.Label;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.awt.event.ActionEvent;
    import java.awt.Color;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    public class welcoma<using> {
    using System,IO;
    JFrame frame;

    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    welcoma window = new welcoma();
    window.frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the application.
    */
    public welcoma() {
    initialize();
    }

    /**
    * Initialize the contents of the frame.
    */
    private void initialize() {
    frame = new JFrame();
    frame.setBackground(Color.BLACK);
    frame.getContentPane().setForeground(Color.WHITE);
    frame.getContentPane().setBackground(new Color(240, 240, 240));
    frame.setBounds(100, 100, 609, 391);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("GENERATE AND WORK");
    btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    filename window1 = new filename();
    window1.frame.setVisible(true);
    } catch (Exception e1) {
    e1.printStackTrace();
    }
    frame.dispose(); //close current frame

    }
    });package exceluserform;

    import javax.swing.JFrame;

    import java.awt.EventQueue;

    import javax.swing.JFrame;

    import java.awt.Desktop;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JTextArea;

    import jxl.Workbook;
    import jxl.write.WritableCell;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;

    import javax.swing.JLabel;
    import ja

  3. Hey!  I couldn't reply to your message on my video – it must have been a 'Linked Comment' or something as there's no reply option =/

    In response to your question about the Atari STe / STFM floppy drives – a PC drive is compatible.  Any 720Kb 3.5" PC FDD will work, you might need to change the drive select jumper depending on the drive, but most just plug straight in and work.

    They aren't IDE btw – the connector is similar, its an IDC connector but only 34 pin.  I believe they use something similar to MFM rather than IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *