Example usage for org.apache.poi.ss.usermodel Row cellIterator

List of usage examples for org.apache.poi.ss.usermodel Row cellIterator

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row cellIterator.

Prototype

Iterator<Cell> cellIterator();

Source Link

Usage

From source file:edms.core.Config.java

License:Open Source License

public static void convertToXlsx(InputStream inStream, java.io.File outputFile) {
    // For storing data into CSV files
    StringBuffer cellValue = new StringBuffer();
    try {/*  w  ww . j  a v  a2 s .c  o m*/
        FileOutputStream fos = new FileOutputStream(outputFile);

        // Get the workbook instance for XLSX file
        XSSFWorkbook wb = new XSSFWorkbook(inStream);

        // Get first sheet from the workbook
        XSSFSheet sheet = wb.getSheetAt(0);

        Row row;
        Cell cell;

        // Iterate through each rows from first sheet
        Iterator<Row> rowIterator = sheet.iterator();

        while (rowIterator.hasNext()) {
            row = rowIterator.next();

            // For each row, iterate through each columns
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                cell = cellIterator.next();

                switch (cell.getCellType()) {

                case Cell.CELL_TYPE_BOOLEAN:
                    cellValue.append(cell.getBooleanCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_NUMERIC:
                    cellValue.append(cell.getNumericCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_STRING:
                    cellValue.append(cell.getStringCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_BLANK:
                    cellValue.append("" + ",");
                    break;

                default:
                    cellValue.append(cell + ",");

                }
            }
        }

        fos.write(cellValue.toString().getBytes());

        fos.close();

    } catch (Exception e) {
        System.err.println("Exception :" + e.getMessage());
    }

}

From source file:edms.core.Config.java

License:Open Source License

public static void convertToXls(InputStream inStream, java.io.File outputFile) {
    // For storing data into CSV files
    StringBuffer cellDData = new StringBuffer();
    try {/*www  .ja  v  a2  s . com*/
        FileOutputStream fos = new FileOutputStream(outputFile);

        // Get the workbook instance for XLS file
        HSSFWorkbook workbook = new HSSFWorkbook(inStream);
        // Get first sheet from the workbook
        HSSFSheet sheet = workbook.getSheetAt(0);
        Cell cell;
        Row row;

        // Iterate through each rows from first sheet
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            row = rowIterator.next();

            // For each row, iterate through each columns
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                cell = cellIterator.next();

                switch (cell.getCellType()) {

                case Cell.CELL_TYPE_BOOLEAN:
                    cellDData.append(cell.getBooleanCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_NUMERIC:
                    cellDData.append(cell.getNumericCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_STRING:
                    cellDData.append(cell.getStringCellValue() + ",");
                    break;

                case Cell.CELL_TYPE_BLANK:
                    cellDData.append("" + ",");
                    break;

                default:
                    cellDData.append(cell + ",");
                }
            }
        }

        fos.write(cellDData.toString().getBytes());
        fos.close();

    } catch (FileNotFoundException e) {
        System.err.println("Exception" + e.getMessage());
    } catch (IOException e) {
        System.err.println("Exception" + e.getMessage());
    }

}

From source file:edu.rice.rems.Scheduler.java

License:Open Source License

/**
 * Extract shift schedule data from excel file
 *
 * @param xlsFile/*  w  ww . ja  v  a 2 s .  co m*/
 * @return data
 */
private static ArrayList<ArrayList<String>> extractData(File xlsFile) {
    ArrayList<ArrayList<String>> data = new ArrayList<>();

    try {
        FileInputStream file = new FileInputStream(xlsFile);

        HSSFWorkbook workbook = new HSSFWorkbook(file);
        HSSFSheet sheet = workbook.getSheetAt(0);

        //Iterate through each rows from first sheet
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            ArrayList<String> newRow = new ArrayList<String>();

            //For each row, iterate through each columns
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                newRow.add(cell.getStringCellValue());
            }
            data.add(newRow);
        }
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return data;
}

From source file:Ekon.PanelVypisFirem.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    JFileChooser fch = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("objects xls xlsx", "xls", "xlsx");
    fch.setFileFilter(filter);//from  w ww.  ja  v  a 2  s . c  om
    int returnVal = fch.showOpenDialog(this);

    try {
        File nazevSouboru = fch.getSelectedFile();
        ArrayList<Firma> list = new ArrayList<>();
        FileInputStream file = new FileInputStream(nazevSouboru.getAbsoluteFile());
        //Create Workbook instance holding reference to .xlsx file
        XSSFWorkbook workbookV = new XSSFWorkbook(nazevSouboru.getAbsolutePath());

        //Get first/desired sheet from the workbook
        XSSFSheet sheetV = workbookV.getSheetAt(0);

        Iterator<Row> rowIT = sheetV.iterator();

        while (rowIT.hasNext()) {
            Row row = rowIT.next();
            Iterator<Cell> cellIt = row.cellIterator();
            ArrayList<String> listO = new ArrayList<>();
            while (cellIt.hasNext()) {
                Cell cell = cellIt.next();
                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    // System.out.print(cell.getNumericCellValue() + " ");

                    listO.add(String.valueOf((int) cell.getNumericCellValue()));
                    break;
                case Cell.CELL_TYPE_STRING:
                    listO.add(cell.getStringCellValue());
                    //System.out.print(cell.getStringCellValue() + " ");
                    break;
                }

            }

            vytvorFirmy.pridejFirmu(new Firma(String.valueOf(listO.get(0)), String.valueOf(listO.get(1)),
                    String.valueOf(listO.get(2)), String.valueOf(listO.get(3)), String.valueOf(listO.get(4)),
                    Integer.valueOf(listO.get(5)), Integer.valueOf(listO.get(6)), String.valueOf(listO.get(7)),
                    Integer.valueOf(listO.get(8))));
        }
        file.close();
        DefaultTableModel model = (DefaultTableModel) tableFirmy.getModel();
        while (model.getRowCount() > 0) {
            model.removeRow(0);
        }
        Iterator it = vytvorFirmy.dejIterator();
        Iterator itN = poleNazvu.iterator();
        Firma f;
        try {

            for (Iterator it1 = it; it1.hasNext();) {
                f = (Firma) it1.next();
                model.addRow(new Object[] { f.getNazevFirmy(), f.getMesto(), f.getUlice(), f.getKraj(),
                        f.getPsc(), f.getKontakt(), f.getEmail(), f.getIco(), f.getDico() });
            }
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(this, "seznam firem je prazdny", "Chyba", 1);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Ekon.PanelVypisZamestnancu.java

private void btnNactiXLSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNactiXLSActionPerformed
    JFileChooser fch = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("objects xls xlsx", "xls", "xlsx");
    fch.setFileFilter(filter);//from w w w. j  av  a 2s. co m
    int returnVal = fch.showOpenDialog(this);

    try {
        File nazevSouboru = fch.getSelectedFile();
        ArrayList<Zamestnanec> list = new ArrayList<>();
        FileInputStream file = new FileInputStream(nazevSouboru.getAbsoluteFile());
        //Create Workbook instance holding reference to .xlsx file
        XSSFWorkbook workbookV = new XSSFWorkbook(nazevSouboru.getAbsolutePath());

        //Get first/desired sheet from the workbook
        XSSFSheet sheetV = workbookV.getSheetAt(0);

        Iterator<Row> rowIT = sheetV.iterator();
        rowIT.next();
        while (rowIT.hasNext()) {
            Row row = rowIT.next();
            Iterator<Cell> cellIt = row.cellIterator();
            ArrayList<String> listO = new ArrayList<>();
            while (cellIt.hasNext()) {
                Cell cell = cellIt.next();
                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    // System.out.print(cell.getNumericCellValue() + " ");

                    listO.add(String.valueOf((int) cell.getNumericCellValue()));
                    break;
                case Cell.CELL_TYPE_STRING:
                    listO.add(cell.getStringCellValue());
                    // System.out.print(cell.getStringCellValue() + " ");
                    break;
                }
            }
            aktualniFirma.pridejZamestnance(new Zamestnanec(listO.get(0), listO.get(1), listO.get(2),
                    listO.get(3), Integer.valueOf(listO.get(4)), listO.get(5), listO.get(6), listO.get(7),
                    listO.get(8), Integer.valueOf(listO.get(9)), Integer.valueOf(listO.get(10)), listO.get(11),
                    listO.get(12)));
        }
        file.close();
        DefaultTableModel model = (DefaultTableModel) tableZamestnanci.getModel();
        while (model.getRowCount() > 0) {
            model.removeRow(0);
        }
        Iterator it = aktualniFirma.dejIteratorZamestnancu();
        try {
            for (Iterator it1 = it; it1.hasNext();) {
                Zamestnanec z = (Zamestnanec) it1.next();
                model.addRow(new Object[] { z.getJmeno(), z.getPrijmeni(), z.getTitul(), z.getMesto(),
                        z.getUlice(), z.getPsc(), z.getKraj(), z.getDatumNarozeni(), z.getRodneCislo(),
                        z.getEmail(), z.getTelefoniCislo(), z.getNarodnost(), z.getPozice() });
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "seznam zamestnancu je prazdny", "Chyba", 1);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    Iterator itF = vytvorFirmy.dejIterator();
    for (Iterator it1 = itF; it1.hasNext();) {
        Firma f = (Firma) it1.next();
        if (aktualniFirma.getNazevFirmy().equals(f.getNazevFirmy())) {
            f.setListZamestanancu(aktualniFirma.getListZamestanancu());
        }
    }
}

From source file:es.SSII2.manager.ExcelManagerAccount.java

public void readAccountExcel() throws FileNotFoundException, IOException {

    FileInputStream file;// ww w  .  j  a va 2  s  .  c o  m
    file = new FileInputStream(new File(excel));

    try (XSSFWorkbook workbook = new XSSFWorkbook(file)) {
        XSSFSheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        Row row;
        // Recorremos todas las filas para mostrar el contenido de cada celda
        while (rowIterator.hasNext()) {
            row = rowIterator.next();

            // Obtenemos el iterator que permite recorres todas las celdas de una fila
            Iterator<Cell> cellIterator = row.cellIterator();
            Cell celda;

            double val;
            DecimalFormat df = new DecimalFormat("#");

            while (cellIterator.hasNext()) {

                celda = cellIterator.next();

                if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 8 && celda.getCellType() != 3) {

                    val = celda.getNumericCellValue();
                    String stringPOI = NumberToTextConverter.toText(val);

                    //anadir la cuenta al arraylist y las posiciones
                    account.addAccount(stringPOI);
                    account.addAccountPos(celda.getRowIndex() + "-" + celda.getColumnIndex());

                }
            }
        }

    }
}

From source file:es.SSII2.manager.ExcelManagerMail.java

public void readAccountExcel() throws FileNotFoundException, IOException {

    FileInputStream file;//w  w  w . j av  a 2 s  .co  m
    file = new FileInputStream(new File(excel));

    try (XSSFWorkbook workbook = new XSSFWorkbook(file)) {
        XSSFSheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        Row row;
        // Recorremos todas las filas para mostrar el contenido de cada celda
        while (rowIterator.hasNext()) {

            workers = new WorkersID();
            row = rowIterator.next();

            // Obtenemos el iterator que permite recorres todas las celdas de una fila
            Iterator<Cell> cellIterator = row.cellIterator();
            Cell celda;

            String celdas;

            while (cellIterator.hasNext()) {

                celda = cellIterator.next();

                if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 0 && celda.getCellType() != 3) {

                    celdas = celda.getStringCellValue();

                    //anadir la cuenta al arraylist y las posiciones
                    workers.setNombre(celdas);

                }

                if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 1 && celda.getCellType() != 3) {

                    celdas = celda.getStringCellValue();

                    //anadir la cuenta al arraylist y las posiciones
                    workers.setApellido1(celdas);

                }
                if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 2 && celda.getCellType() != 3) {

                    celdas = celda.getStringCellValue();

                    //anadir la cuenta al arraylist y las posiciones
                    workers.setApellido2(celdas);

                }
                if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 6 && celda.getCellType() != 3) {

                    celdas = celda.getStringCellValue();

                    //anadir la cuenta al arraylist y las posiciones
                    workers.setEmpresa(celdas);

                }
            }

            //se mete los datos en el arraylist 
            if (workers.getNombre() != null)
                arrayWorkers.add(workers);
        }

    }

    //System.out.println(arrayWorkers.get(6).getApellido1());
    email = new WorkersEmail(arrayWorkers);
    email.creacionCorreos();
}

From source file:eventHandlers.CompareDrotVSRoster.java

public void colorXLSXFile(String leaveXlsxRoster) throws FileNotFoundException, IOException {
    File xlsxFile = new File(leaveXlsxRoster);
    try {//  w  w  w . j a  v  a  2s.c o m
        FileInputStream fis = new FileInputStream(xlsxFile);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);

        //Return first sheet from the XLSX workbook
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);

        //Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = mySheet.iterator();
        // Traversing over each row of XLSX file
        if (rowIterator.hasNext()) {
            Row headerRow = rowIterator.next(); //skip the header row
            Iterator<Cell> it = headerRow.cellIterator();
            int numCell = 0;
            // List<String> keyList = new ArrayList<>(); //keep track info of each column
            while (it.hasNext()) {
                //keyList.add(it.next().getStringCellValue());   
                it.next();
                numCell++;
            }

            if (numCell == GlobalVar.SIGNED_LEAVE_TITLES.length) { // correct xlsx file                 
                int rowNum = 1;
                while (rowIterator.hasNext()) {
                    Row row = rowIterator.next();
                    //row.getRowStyle();
                    rowNum++;
                }
                for (int i = 1; i < rowNum; i++) {
                    Row row = mySheet.getRow(i);
                    foregroundColorSetUp(row, myWorkBook); //check each row and update foreground color
                }
                fis.close();
                FileOutputStream output;
                String targetFile = null;
                String[] names = leaveXlsxRoster.split("\\.");
                if (!names[0].equals(leaveXlsxRoster)) { //doesn't contain surfix
                    targetFile = names[0] + "COLORED.xlsx";
                } else {
                    targetFile = leaveXlsxRoster + "COLORED.xlsx";
                }
                output = new FileOutputStream(targetFile);
                myWorkBook.write(output);
                output.close();
                //myWorkBook.write(output);

            } else {
                JOptionPane.showMessageDialog(null, "XLSX file doesn't contain correct info!");
            }
        } else {
            JOptionPane.showMessageDialog(null, "XLSX file is empty!");
            System.out.println("The xlsx file is empty!");
        }

        // finds the work book in stance for XLSX file
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Xlsx file not found!");
    }
}

From source file:eventHandlers.XLSX2BatchHandler.java

public void exportBatchFile(String xlsxFileName, String batchFileName) throws IOException {
    File myFile = new File(xlsxFileName);
    FileOutputStream outputFile = new FileOutputStream(batchFileName); //allow to append
    PrintStream output = new PrintStream(outputFile);
    try {//from w w w.  j a v a  2s  .c  om
        FileInputStream fis = new FileInputStream(myFile);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);

        //Return first sheet from the XLSX workbook
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Map<String, Map<String, List<String>>> leaves = new HashMap<String, Map<String, List<String>>>();
        //Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = mySheet.iterator();
        int lineCount = 1;
        // Traversing over each row of XLSX file
        if (rowIterator.hasNext()) {

            Row headerRow = rowIterator.next(); //skip the header row
            Iterator<Cell> it = headerRow.cellIterator();
            int numCell = 0;
            List<String> keyList = new ArrayList<String>(); //keep track info of each column

            while (it.hasNext()) {
                keyList.add(it.next().getStringCellValue());
                numCell++;
            }

            if (numCell == GlobalVar.LEAVE_TITLES_V1.length) { // check if the excel is the leave roster
                int globalCount = 1;
                MyDate soDate = new MyDate();
                MyDate siDate = new MyDate();
                while (rowIterator.hasNext()) {
                    //int cellCount = 0;             
                    lineCount++;
                    Row row = rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    Map<String, String> container = new HashMap<String, String>();
                    int keys = 0; //index of the cell
                    // reset date every row
                    Boolean soDateAssigned = false;
                    Boolean siDateAssigned = false;
                    while (cellIterator.hasNext()) {
                        Cell cell = cellIterator.next();
                        int type = cell.getCellType();
                        // distinguish the cell content, in the xlsx file, 
                        // SSN and dates are CELL_TYPE_NUMERIC 
                        // number of leave days is CELL_TYPE_FORMULA
                        // the rest is CELL_TYPE_STRING
                        if (type == HSSFCell.CELL_TYPE_NUMERIC && keys != GlobalVar.LAST4_CELL_INDEX_V1) { // dates
                            DataFormatter df = new DataFormatter();
                            //SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd");   
                            String dateString = df.formatCellValue(cell);
                            if (!soDateAssigned && !siDateAssigned) {
                                //System.out.println(dateString);  //150201
                                soDate = new MyDate(dateString);
                                soDateAssigned = true;
                            } else if (soDateAssigned && !siDateAssigned) {
                                siDate = new MyDate(dateString);
                                siDateAssigned = true;
                            } else { // do nothing
                                //System.out.println("We should never come here!");
                            }
                            //String value = (int) cell.getNumericCellValue() + ""; // number of days
                            container.put(keyList.get(keys), dateString);
                            // System.out.println(value);
                            //                            } else if (type == HSSFCell.CELL_TYPE_STRING 
                            //                                    && keys == GlobalVar.SSN_CELL_INDEX){  
                        } else if (keys == GlobalVar.LAST4_CELL_INDEX_V1) {
                            DataFormatter df = new DataFormatter();
                            //SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd");   
                            String lastFour = df.formatCellValue(cell); //return ***-**-****
                            //                                String lastFour = cell.getStringCellValue();
                            //ssnString = ssnString.replace("-","");
                            lastFour = GlobalVar.last4Generator(lastFour);
                            // System.out.println("SSN:  " + lastFour);
                            container.put(keyList.get(keys), lastFour);
                        } else if (keys == GlobalVar.LAST_NAME_CELL_INDEX_V1) {
                            String value = cell.getStringCellValue();
                            container.put(keyList.get(keys), value);
                            //                            } else if (type == HSSFCell.CELL_TYPE_FORMULA) {
                            //                                    String days = soDate.getDaysDifftoString(siDate);
                            //                                    container.put(keyList.get(keys),days); 
                            //                                    //reset the dates  
                        } else if (type == HSSFCell.CELL_TYPE_STRING) {
                            String value;
                            if (keys == GlobalVar.LEAVE_AREA_CELL_INDEX_V1) {
                                String str2 = cell.getStringCellValue();
                                //System.out.println(str2);
                                value = GlobalVar.getDMOLeaveArea(str2);
                                //System.out.println(value);
                            } else if (keys == GlobalVar.LEAVE_TYPE_CELL_INDEX_V1) {
                                value = GlobalVar.getDMOLeaveType(cell.getStringCellValue());
                                //System.out.println(value);
                            } else {
                                value = cell.getStringCellValue();
                            }
                            container.put(keyList.get(keys), value);
                        }
                        keys++;
                    }

                    //    public static final String[] SIGNED_LEAVE_TITLES = {"Ctrl Number", 
                    //            "SSN", "Last Name", "Sign-in Date", "Sign-out Date", "Leave Area",
                    //        "Leave Type", "Num of Days", "First Five","Projected Sign-in Date", "Projected Sign-out Date"};
                    //      make sure the key mataches the name in the header

                    String ctrlNum = container.get(keyList.get(GlobalVar.CTRL_NUM_CELL_INDEX_V1));
                    String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_CELL_INDEX_V1));
                    String lastFour = container.get(keyList.get(GlobalVar.LAST4_CELL_INDEX_V1)); // last four
                    // lastName = DB.getSSN(lastName, lastFour);

                    String signOutDate = container.get(keyList.get(GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V1));
                    String signInDate = container.get(keyList.get(GlobalVar.SIGN_IN_DATE_CELL_INDEX_V1));
                    String leaveArea = container.get(keyList.get(GlobalVar.LEAVE_AREA_CELL_INDEX_V1));
                    String leaveType = container.get(keyList.get(GlobalVar.LEAVE_TYPE_CELL_INDEX_V1));

                    //Map<String, String> thisMap = DB.get(thislastName, lastFour);
                    String SSN = DB.getSSN(lastName, lastFour);
                    //System.out.println("xlsx2batchHandler.java" + SSN + "+" + lastName);
                    String first5 = DB.getFirst5(lastName, lastFour);
                    String leaveDays = GlobalVar.computeNumOfDays(new MyDate(signOutDate),
                            new MyDate(signInDate));

                    int leaveMsg = GlobalVar.checkLeaves(ctrlNum, SSN, signOutDate, signInDate, leaves);
                    if (leaveMsg == GlobalVar.GOOD_LEAVE) {
                        String lc = GlobalVar.LC;
                        String inputSource = ctrlNum.substring(0, 2);
                        String cycle = GlobalVar.CYCLE;
                        String data = "0SB03" + SSN + first5 + signOutDate + signInDate + leaveType + leaveDays
                                + leaveArea + ctrlNum + "000" + GlobalVar.whiteSpace() + lc + inputSource
                                + cycle + "@" + GlobalVar.globalCountGenerator(globalCount);
                        output.println(data);
                        globalCount++;
                    } else if (leaveMsg == GlobalVar.OVERLAP_LEAVE) {
                        //String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_INDEX));
                        String msg = "Line" + lineCount + " : " + ctrlNum + " " + lastName + " " + signOutDate
                                + " - " + signInDate;
                        JOptionPane.showMessageDialog(null,
                                msg + "\n is overlapping with a leave posted before.");
                    } else if (leaveMsg == GlobalVar.DUPLICATE_CTRL_NUM) {
                        //String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_INDEX));
                        JOptionPane.showMessageDialog(null, "Line" + lineCount + " : Duplicate control number "
                                + ctrlNum + " for " + lastName + ".");
                    }
                }
                fis.close();
                output.close();
            } else {
                JOptionPane.showMessageDialog(null, "XLSX file doesn't contain correct info!");
            }
        } else {
            JOptionPane.showMessageDialog(null, "XLSX file is empty!");
            System.out.println("The xlsx file is empty!");
        }

        // finds the work book in stance for XLSX file
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Xlsx file not found!");
        Logger.getLogger(XLSX2BatchHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:excel.Excel.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//from w w  w  .  ja v  a 2s .c  om
 */
public static void main(String args[]) throws IOException {
    Thread a;

    //        String nameFile = "C:\\Users\\dfcastellanosc.SOPORTECOS\\Downloads\\Files\\Informacin Etapa Productiva.xlsx";

    //        Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + nameFile);

    FileInputStream file = new FileInputStream(
            new File("C:\\Users\\dfcastellanosc.SOPORTECOS\\Documents\\registroempleados.xlsx"));

    try (XSSFWorkbook workbook = new XSSFWorkbook(file)) {
        XSSFSheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();

        Row row;

        while (rowIterator.hasNext()) {

            row = rowIterator.next();

            Iterator<Cell> cellIterator = row.cellIterator();

            Cell celda;

            while (cellIterator.hasNext()) {

                celda = cellIterator.next();

                switch (celda.getCellType()) {

                case Cell.CELL_TYPE_NUMERIC:

                    if (DateUtil.isCellDateFormatted(celda)) {

                        if (celda.getColumnIndex() == 17) {
                            System.out.println("|" + celda.getDateCellValue() + "|");
                        } else {
                            System.out.print("|" + celda.getDateCellValue() + "|");
                        }

                    } else {

                        Double ds = celda.getNumericCellValue();
                        Long pt = ds.longValue();

                        if (celda.getColumnIndex() == 17) {
                            System.out.println("|" + pt + "|");
                        } else {
                            System.out.print("|" + pt + "|");
                        }
                    }
                    break;

                case Cell.CELL_TYPE_STRING:
                    if (celda.getColumnIndex() == 17) {
                        System.out.println("|" + celda.getStringCellValue() + "|");
                    } else {
                        System.out.print("|" + celda.getStringCellValue() + "|");
                    }

                    break;

                case Cell.CELL_TYPE_BOOLEAN:

                    if (celda.getColumnIndex() == 17) {
                        System.out.println("|" + celda.getBooleanCellValue() + "|");
                    } else {
                        System.out.print("|" + celda.getBooleanCellValue() + "|");
                    }

                    break;

                }

            }

        }
        workbook.close();
    }

}