com.excel.javafx.frames.MainFrame.java Source code

Java tutorial

Introduction

Here is the source code for com.excel.javafx.frames.MainFrame.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.excel.javafx.frames;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.table.DefaultTableModel;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author harsimran
 */
public class MainFrame extends javax.swing.JFrame {

    private static DefaultTableModel tableModel;
    Object columnname[] = { "SOURCEFILE", "DESTFILE", "SOURCEROW", "DESTROW", "SOURCECOLUMN", "DESTCOLUMN",
            "EXPECTED_VALUE", "ACTUAL_VALUE" };
    public File sourceFileName = null;
    public File destFileName = null;
    private int rowcount = 500;
    private List<String> sourceRow = null;
    private List<String> destRow = null;
    private List<String> sourceColumn = null;
    private List<String> destColumn = null;
    private List<String> expectedValue = null;
    private List<String> actualValue = null;

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        tableModel = new DefaultTableModel(columnname, 8);
        tableModel.setRowCount(rowcount);
        jTable1.setModel(tableModel);
        for (int i = 0; i < rowcount; i++) {
            tableModel.setValueAt(i + 1, i, 0);
            for (int j = 1; j < 8; j++) {
                tableModel.setValueAt("", i, j);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        DestinationBtn = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        SourceBtn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        destSheetSelector = new javax.swing.JComboBox<>();
        jLabel3 = new javax.swing.JLabel();
        sourceSheetSelector = new javax.swing.JComboBox<>();
        jLabel5 = new javax.swing.JLabel();
        CompareBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        sourceColumnList = new javax.swing.JList<>();
        jScrollPane3 = new javax.swing.JScrollPane();
        destColumnList = new javax.swing.JList<>();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        DestinationBtn.setText("Choose file...");
        DestinationBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DestinationBtnActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
        jLabel4.setText("Excel Comparison Tool");

        jLabel1.setText("Source File");

        SourceBtn.setText("Choose file...");
        SourceBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SourceBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("Destination File");

        destSheetSelector.setModel(
                new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        destSheetSelector.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                destSheetSelectorItemStateChanged(evt);
            }
        });

        jLabel3.setText("Sheet Filter");

        sourceSheetSelector.setModel(
                new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        sourceSheetSelector.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                sourceSheetSelectorItemStateChanged(evt);
            }
        });
        sourceSheetSelector.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sourceSheetSelectorMouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                sourceSheetSelectorMouseEntered(evt);
            }

            public void mouseReleased(java.awt.event.MouseEvent evt) {
                sourceSheetSelectorMouseReleased(evt);
            }
        });
        sourceSheetSelector.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sourceSheetSelectorActionPerformed(evt);
            }
        });

        jLabel5.setText("Sheet Filter");

        CompareBtn.setText("Compare");
        CompareBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CompareBtnActionPerformed(evt);
            }
        });

        jTable1.setModel(
                new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null, null }, { null, null, null, null },
                                { null, null, null, null }, { null, null, null, null } },
                        new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        jScrollPane1.setViewportView(jTable1);

        jScrollPane2.setViewportView(sourceColumnList);

        jScrollPane3.setViewportView(destColumnList);

        jButton1.setText("Show Columns");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Show Columns");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGap(228, 228, 228).addComponent(
                                                jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(
                                                jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 912,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup().addGap(54, 54, 54)
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                        .addComponent(jButton1,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE)
                                                                        .addComponent(
                                                                                jScrollPane2,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                0, Short.MAX_VALUE)
                                                                        .addComponent(SourceBtn,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE))
                                                                .addComponent(
                                                                        sourceSheetSelector,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel5).addComponent(jLabel1))
                                                        .addGap(65, 65, 65)
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(jButton2,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(jLabel3)
                                                                .addComponent(destSheetSelector,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel2)
                                                                .addComponent(jScrollPane3,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(DestinationBtn,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)))
                                                .addGroup(layout.createSequentialGroup().addGap(151, 151, 151)
                                                        .addComponent(CompareBtn))))
                                .addContainerGap(19, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addGap(12, 12, 12).addComponent(jLabel4).addGap(18, 18, 18).addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(layout
                                .createSequentialGroup().addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SourceBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(sourceSheetSelector, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jButton1).addComponent(jButton2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18).addComponent(CompareBtn).addGap(30, 30, 30))
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(DestinationBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(destSheetSelector, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 251,
                                                Short.MAX_VALUE)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 199,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void DestinationBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DestinationBtnActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            destFileName = fileChooser.getSelectedFile();
            getDestinationFileHeaders(destFileName);
            System.out.print(destFileName.getName());
        }
    }//GEN-LAST:event_DestinationBtnActionPerformed

    private void SourceBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SourceBtnActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            sourceFileName = fileChooser.getSelectedFile();
            getSourceFileHeaders(sourceFileName);
            System.out.print(sourceFileName.getName());
        }
    }//GEN-LAST:event_SourceBtnActionPerformed

    private void getSourceFileHeaders(File file) {
        try {
            FileInputStream sourceFile1 = new FileInputStream(file);
            XSSFWorkbook workbook1 = new XSSFWorkbook(sourceFile1);
            sourceSheetSelector.removeAllItems(); //to clear existing headers
            for (int sheetno = 0; sheetno < workbook1.getNumberOfSheets(); sheetno++) {
                sourceSheetSelector.addItem(workbook1.getSheetName(sheetno));
            }
            //sourceColumnSelector();     // to fill columnSelection
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void getDestinationFileHeaders(File file) {
        try {
            FileInputStream destFile = new FileInputStream(file);
            XSSFWorkbook workbook1 = new XSSFWorkbook(destFile);
            destSheetSelector.removeAllItems(); //to clear existing headers

            for (int sheetno = 0; sheetno < workbook1.getNumberOfSheets(); sheetno++) {
                destSheetSelector.addItem(workbook1.getSheetName(sheetno));
            }
            //destinationColumnSelector();     // to fill columnSelection
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void CompareBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CompareBtnActionPerformed
        try {
            // get input excel files
            FileInputStream sourceFile = new FileInputStream(sourceFileName);
            FileInputStream destFile = new FileInputStream(destFileName);

            // Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook sourcebook = new XSSFWorkbook(sourceFile);
            XSSFWorkbook destbook = new XSSFWorkbook(destFile);

            // Get first/desired sheet from the workbook
            XSSFSheet sourceSheet = sourcebook.getSheet(sourceSheetSelector.getSelectedItem().toString());
            XSSFSheet destSheet = destbook.getSheet(destSheetSelector.getSelectedItem().toString());

            // Compare sheets
            if (compareTwoSheets(sourceSheet, destSheet)) {
                System.out.println("\n\nThe two excel sheets are Equal");
            } else {
                System.out.println("\n\nThe two excel sheets are Not Equal");
            }

            //close files
            sourceFile.close();
            destFile.close();

            //update table values
            int emptyrow = 0;
            for (int rownum = 0; rownum < rowcount; rownum++) {
                if (!tableModel.getValueAt(rownum, 1).toString().equals("")) {
                    emptyrow++;
                }
            }
            for (int rowno = 0; rowno <= expectedValue.size(); rowno++) {
                tableModel.setValueAt(sourceFileName.getName(), emptyrow, 1);
                jTable1.setValueAt(destFileName.getName(), emptyrow, 2);
                jTable1.setValueAt(sourceRow.get(rowno), emptyrow, 3);
                jTable1.setValueAt(destRow.get(rowno), emptyrow, 4);
                jTable1.setValueAt(sourceColumnList.getSelectedValue(), emptyrow, 5);
                jTable1.setValueAt(destColumnList.getSelectedValue(), emptyrow, 6);
                jTable1.setValueAt(expectedValue.get(rowno), emptyrow, 7);
                jTable1.setValueAt(actualValue.get(rowno), emptyrow, 8);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }//GEN-LAST:event_CompareBtnActionPerformed

    private void sourceColumnSelector() {
        FileInputStream sourceFile1 = null;
        final DefaultListModel model = new DefaultListModel();

        try {
            sourceFile1 = new FileInputStream(sourceFileName);
            XSSFWorkbook workbook1 = new XSSFWorkbook(sourceFile1);
            XSSFSheet sheet = workbook1.getSheet(sourceSheetSelector.getSelectedItem().toString());
            int columncount = sheet.getRow(0).getLastCellNum();

            for (int columnno = 0; columnno < columncount; columnno++) {
                model.addElement(sheet.getRow(0).getCell(columnno).toString());
            }
            sourceColumnList.setModel(model);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                sourceFile1.close();
            } catch (IOException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void destinationColumnSelector() {
        FileInputStream destFile1 = null;
        final DefaultListModel model = new DefaultListModel();

        try {
            destFile1 = new FileInputStream(destFileName);
            XSSFWorkbook workbook1 = new XSSFWorkbook(destFile1);
            XSSFSheet sheet = workbook1.getSheet(destSheetSelector.getSelectedItem().toString());
            int columncount = sheet.getRow(0).getLastCellNum();

            for (int columnno = 0; columnno < columncount; columnno++) {
                model.addElement(sheet.getRow(0).getCell(columnno).toString());
            }
            destColumnList.setModel(model);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                destFile1.close();
            } catch (IOException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void sourceSheetSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceSheetSelectorActionPerformed

    }//GEN-LAST:event_sourceSheetSelectorActionPerformed

    private void sourceSheetSelectorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sourceSheetSelectorItemStateChanged
        // TODO add your handling code here:

    }//GEN-LAST:event_sourceSheetSelectorItemStateChanged

    private void sourceSheetSelectorMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sourceSheetSelectorMouseReleased
        // TODO add your handling code here:

    }//GEN-LAST:event_sourceSheetSelectorMouseReleased

    private void sourceSheetSelectorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sourceSheetSelectorMouseClicked
        // TODO add your handling code here:
        // sourcecount++;
    }//GEN-LAST:event_sourceSheetSelectorMouseClicked

    private void sourceSheetSelectorMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sourceSheetSelectorMouseEntered
        // TODO add your handling code here:

    }//GEN-LAST:event_sourceSheetSelectorMouseEntered

    private void destSheetSelectorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_destSheetSelectorItemStateChanged

    }//GEN-LAST:event_destSheetSelectorItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        sourceColumnSelector();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        destinationColumnSelector();
    }//GEN-LAST:event_jButton2ActionPerformed

    // Compare Two Sheets
    public boolean compareTwoSheets(XSSFSheet sheet1, XSSFSheet sheet2) {
        sourceRow = new ArrayList<String>();
        destRow = new ArrayList<String>();
        int firstRow1 = sheet1.getFirstRowNum() + 1;
        int lastRow1 = sheet1.getLastRowNum();
        boolean equalSheets = true;
        for (int i = firstRow1; i <= lastRow1; i++) {

            System.out.println("\n\nComparing Row " + i);

            XSSFRow row1 = sheet1.getRow(i);
            XSSFRow row2 = sheet2.getRow(i);
            if (!compareTwoRows(row1, row2)) {
                equalSheets = false;
                System.out.println("Row " + i + " - Not Equal");
                sourceRow.add("Row" + i);
                destRow.add("Row" + i);
            } else {
                System.out.println("Row " + i + " - Equal");
            }
        }
        return equalSheets;
    }

    // Compare Two Rows
    public boolean compareTwoRows(XSSFRow row1, XSSFRow row2) {

        expectedValue = new ArrayList<String>();
        actualValue = new ArrayList<String>();
        if ((row1 == null) && (row2 == null)) {
            return true;
        } else if ((row1 == null) || (row2 == null)) {
            return false;
        }

        boolean equalRows = true;

        // Compare all cells in a row
        //for(int i=firstCell1; i <= lastCell1; i++) {

        XSSFCell cell1 = row1.getCell(sourceColumnList.getSelectedIndex());
        XSSFCell cell2 = row2.getCell(destColumnList.getSelectedIndex());
        if (!compareTwoCells(cell1, cell2)) {
            equalRows = false;
            cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
            System.err.println("       Cell " + cell1.getStringCellValue() + " - NOt Equal");
            System.err.println("       Cell " + cell2.getStringCellValue() + " - NOt Equal");
            expectedValue.add(cell1.getStringCellValue());
            actualValue.add(cell2.getStringCellValue());
        } else {
            System.out.println("       Cell " + cell2 + " - Equal");
        }
        // }
        return equalRows;
    }

    // Compare Two Cells
    public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) {
        if ((cell1 == null) && (cell2 == null)) {
            return true;
        } else if ((cell1 == null) || (cell2 == null)) {
            return false;
        }

        boolean equalCells = false;
        int type1 = cell1.getCellType();
        int type2 = cell2.getCellType();
        if (type1 == type2) {
            if (cell1.getCellStyle().equals(cell2.getCellStyle())) {
                // Compare cells based on its type
                switch (cell1.getCellType()) {
                case HSSFCell.CELL_TYPE_FORMULA:
                    if (cell1.getCellFormula().equals(cell2.getCellFormula())) {
                        equalCells = true;
                    }
                    break;
                case HSSFCell.CELL_TYPE_NUMERIC:
                    if (cell1.getNumericCellValue() == cell2.getNumericCellValue()) {
                        equalCells = true;
                    }
                    break;
                case HSSFCell.CELL_TYPE_STRING:
                    if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
                        equalCells = true;
                    }
                    break;
                case HSSFCell.CELL_TYPE_BLANK:
                    if (cell2.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
                        equalCells = true;
                    }
                    break;
                case HSSFCell.CELL_TYPE_BOOLEAN:
                    if (cell1.getBooleanCellValue() == cell2.getBooleanCellValue()) {
                        equalCells = true;
                    }
                    break;
                case HSSFCell.CELL_TYPE_ERROR:
                    if (cell1.getErrorCellValue() == cell2.getErrorCellValue()) {
                        equalCells = true;
                    }
                    break;
                default:
                    if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
                        equalCells = true;
                    }
                    break;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
        return equalCells;
    }

    /**
     * 
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CompareBtn;
    private javax.swing.JButton DestinationBtn;
    private javax.swing.JButton SourceBtn;
    private javax.swing.JList<String> destColumnList;
    private javax.swing.JComboBox<String> destSheetSelector;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JList<String> sourceColumnList;
    private javax.swing.JComboBox<String> sourceSheetSelector;
    // End of variables declaration//GEN-END:variables
}