Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook XSSFWorkbook

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook XSSFWorkbook

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFWorkbook XSSFWorkbook.

Prototype

public XSSFWorkbook(PackagePart part) throws IOException 

Source Link

Document

Constructs a XSSFWorkbook object using Package Part.

Usage

From source file:TaskAdder.java

static void addtask(String task, String comments, String username, String excel_path) {
    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();

    FileInputStream file = null;/*from   w  w w.j  a  v a  2 s .c  o  m*/
    try {
        file = new FileInputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Create Workbook instance holding reference to .xlsx file
    XSSFWorkbook workbook = null;
    try {
        workbook = new XSSFWorkbook(file);
    } catch (IOException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Get first/desired sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(0);
    int rownum = sheet.getLastRowNum();
    //Blank workbook
    Row row = sheet.createRow(rownum + 1);

    Cell usernameCell = row.createCell(0);
    usernameCell.setCellValue(username);
    Cell taskCell = row.createCell(1);
    taskCell.setCellValue(task);
    Cell statusCell = row.createCell(2);
    statusCell.setCellValue("In-Progress");
    Cell timestampCell = row.createCell(3);
    timestampCell.setCellValue(df.format(dateobj).toString());
    Cell commentsCell = row.createCell(5);
    commentsCell.setCellValue(comments);

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        workbook.write(out);
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:TaskAdder.java

static void addAllTask(String task, String comments, String username, String excel_path) {
    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();

    FileInputStream file = null;//from www.  j a v a  2  s  .  co  m
    try {
        file = new FileInputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Create Workbook instance holding reference to .xlsx file
    XSSFWorkbook workbook = null;
    try {
        workbook = new XSSFWorkbook(file);
    } catch (IOException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Get first/desired sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(1);
    int rownum = sheet.getLastRowNum();
    //Blank workbook
    Row row = sheet.createRow(rownum + 1);

    Cell usernameCell = row.createCell(0);
    usernameCell.setCellValue(username);
    Cell taskCell = row.createCell(1);
    taskCell.setCellValue(task);
    Cell statusCell = row.createCell(2);
    statusCell.setCellValue("Task Created");
    Cell timestampCell = row.createCell(3);
    timestampCell.setCellValue(df.format(dateobj).toString());
    Cell commentsCell = row.createCell(4);
    commentsCell.setCellValue(comments);

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        workbook.write(out);
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Authenticator.java

static boolean authenticate(String username, String path) {
    int i = 0;//from  ww  w  .  j  a v  a2 s .co  m
    try {
        FileInputStream f_input = new FileInputStream(new File(path));
        XSSFWorkbook workbook = new XSSFWorkbook(f_input);
        XSSFSheet sheet = workbook.getSheetAt(0);
        int rows_number = sheet.getLastRowNum();
        System.out.println(rows_number);
        XSSFRow row_user = null;
        XSSFCell cell_user = null;
        for (int iterator = 1; iterator <= rows_number; iterator++) {
            row_user = sheet.getRow(iterator);
            cell_user = row_user.getCell(0);
            String valid_username = cell_user.getStringCellValue();
            if (username.equals(valid_username)) {
                System.out.println("valid user");
                return true;
            }
        }
        return false;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:ImporteerExcelsheet.java

public void importeerExcelsheet(String filePath) {
    try {/*from w ww  .  j a  va 2  s.c  om*/
        FileInputStream file = new FileInputStream(new File(filePath));

        if (filePath.toLowerCase().indexOf(xlsx.toLowerCase()) != -1) {
            XSSFWorkbook wbXlsx = new XSSFWorkbook(file);
            sheet = wbXlsx.getSheetAt(0);
            Row row = sheet.getRow(3);
            Cell cell = row.getCell(1);

            try {
                // convert String dd-mm-yyyy naar Date yyyy-mm-dd 
                String excelDatum1 = cell.getStringCellValue();
                Date date = new SimpleDateFormat("dd-MM-yyyy").parse(excelDatum1);
                this.excelDatum = this.formatter.format(date);
            } catch (Exception e) {
                double date1 = cell.getNumericCellValue();
                //convert excel double naar datum
                Date date2 = DateUtil.getJavaDate((double) date1);
                this.excelDatum = new SimpleDateFormat("yyyy-MM-dd").format(date2);
            }
            //Iterate through each rows one by one
            rowIterator = sheet.iterator();
        } else {
            HSSFWorkbook wbXls = new HSSFWorkbook(file);
            sheet1 = wbXls.getSheetAt(0);
            Row row = sheet1.getRow(3);
            Cell cell = row.getCell(1);

            // convert String dd-mm-yyyy naar Date yyyy-mm-dd 
            try {
                String excelDatum1 = cell.getStringCellValue();
                Date date = new SimpleDateFormat("dd-MM-yyyy").parse(excelDatum1);
                this.excelDatum = this.formatter.format(date);
            } catch (Exception e) {
                double date1 = cell.getNumericCellValue();
                //convert excel double naar datum
                Date date2 = DateUtil.getJavaDate((double) date1);
                this.excelDatum = new SimpleDateFormat("yyyy-MM-dd").format(date2);
            }
            //Iterate through each rows one by one
            rowIterator = sheet1.iterator();
        }

        //Iterate through each rows one by one
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            //skip first 5 rows
            if (row.getRowNum() == 0 || row.getRowNum() == 1 || row.getRowNum() == 2 || row.getRowNum() == 3
                    || row.getRowNum() == 4) {
                continue;
            }

            //For each row, iterate through all the columns
            Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                //Check the cell type and format accordingly
                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    //                            System.out.print(cell.getNumericCellValue() + "\t");
                    break;
                case Cell.CELL_TYPE_STRING:
                    //                            System.out.print(cell.getStringCellValue() + "\t");
                    break;
                case Cell.CELL_TYPE_BLANK:
                    //                            System.out.print(cell.getStringCellValue() + "\t");
                    break;
                case Cell.CELL_TYPE_FORMULA:
                    //                            System.out.print(cell.getStringCellValue() + "\t");
                    break;
                }
            }
            // Tabel client
            int kaartnummer = (int) row.getCell(0).getNumericCellValue();
            String naam = row.getCell(1).getStringCellValue();
            String naamPartner = row.getCell(2).getStringCellValue();
            String telefoonnummer = row.getCell(3).getStringCellValue();
            String email = row.getCell(4).getStringCellValue();
            String mobiel = row.getCell(5).getStringCellValue();
            int aantalPersonen = (int) row.getCell(6).getNumericCellValue();
            int aantalPersonenInDeNorm = (int) row.getCell(7).getNumericCellValue();
            double gebruikInMaanden = (double) row.getCell(8).getNumericCellValue();
            String idSoort = row.getCell(9).getStringCellValue();
            //convert excel double naar datum
            double datumUitgifteId1 = row.getCell(10).getNumericCellValue();
            if (datumUitgifteId1 == 0.0) {
                this.datumUitgifteId = null;
            } else {
                Date datumUitgifteId2 = DateUtil.getJavaDate((double) datumUitgifteId1);
                this.datumUitgifteId = new SimpleDateFormat("yyyy-MM-dd").format(datumUitgifteId2);
            }
            ////////////////////////////////////////////////////////////////////////////////////
            String idNummer = row.getCell(11).getStringCellValue();
            String plaatsUitgifteId = row.getCell(12).getStringCellValue();
            String adres = row.getCell(13).getStringCellValue();
            String postcode = row.getCell(14).getStringCellValue();
            String plaats = row.getCell(15).getStringCellValue();
            String status = row.getCell(16).getStringCellValue();

            // Tabel intake
            // kaartnummer gaat hier ook in de query
            String intaker = row.getCell(17).getStringCellValue();
            double intakeDatum1 = row.getCell(18).getNumericCellValue();
            //convert excel double naar datum
            Date intakeDatum2 = DateUtil.getJavaDate((double) intakeDatum1);
            String intakeDatum = new SimpleDateFormat("yyyy-MM-dd").format(intakeDatum2);
            /////////////////////////////////////////////////////////////////////////
            double startDatumUitgifte1 = row.getCell(19).getNumericCellValue();
            //convert excel double naar datum
            Date startDatumUitgifte2 = DateUtil.getJavaDate((double) startDatumUitgifte1);
            String startDatumUitgifte = new SimpleDateFormat("yyyy-MM-dd").format(startDatumUitgifte2);
            //////////////////////////////////////////////////////////////////////////////////
            double datumHerintake1 = row.getCell(20).getNumericCellValue();
            //convert excel double naar datum
            Date datumHerintake2 = DateUtil.getJavaDate((double) datumHerintake1);
            String datumHerintake = new SimpleDateFormat("yyyy-MM-dd").format(datumHerintake2);
            /////////////////////////////////////////////////////////////////////////////////
            // Tabel Stopt
            double datumStopzetting1 = row.getCell(21).getNumericCellValue();
            //convert excel numbers naar datum
            Date datumStopzetting2 = DateUtil.getJavaDate((double) datumStopzetting1);
            String datumStopzetting = new SimpleDateFormat("yyyy-MM-dd").format(datumStopzetting2);
            //////////////////////////////////////////////////////////////////////////////////////
            String redenStopzetting = row.getCell(22).getStringCellValue();

            // Tabel verwijzer
            String verwijzerNaam = row.getCell(23).getStringCellValue();
            String verwijzersDoorContactpersoon1 = row.getCell(24).getStringCellValue();
            String verwijzersDoorContactpersoon = verwijzersDoorContactpersoon1.toLowerCase();
            String verwijzersDoorTelefoonnummer = row.getCell(25).getStringCellValue();
            String verwijzersDoorEmail = row.getCell(26).getStringCellValue();
            String verwijzersNaar = row.getCell(27).getStringCellValue();
            String verwijzersNaarContactpersoon = row.getCell(28).getStringCellValue();
            String verwijzersNaarTelefoonnummer = row.getCell(29).getStringCellValue();
            String verwijzersNaarEmail = row.getCell(30).getStringCellValue();

            // Uitgiftepunt gaat in de tabel intake
            String uitgiftepunt = row.getCell(31).getStringCellValue();

            // PakketSoort gaat in de tabel client
            String pakketSoort = row.getCell(32).getStringCellValue();

            // Query's om de excelsheet in de database te krijgen
            SQLExcelSheetInsert excelSQL = new SQLExcelSheetInsert();
            SQLget getSQL = new SQLget();

            // Losse query uit de tabel om bepaalde gegevens te krijgen om te controleren of die al bestaat of niet
            int Verwijzer = getSQL.getVerwijzernr(verwijzerNaam, verwijzersDoorContactpersoon);
            int checkKaartnr = getSQL.getCheckKaartnummer(kaartnummer);
            int checkUitgiftepunt = getSQL.getUitgiftepunt(uitgiftepunt);

            if (Verwijzer == 0) {
                excelSQL.insertExcelVerwijzer(verwijzerNaam, verwijzersDoorContactpersoon,
                        verwijzersDoorTelefoonnummer, verwijzersDoorEmail, verwijzersNaar,
                        verwijzersNaarContactpersoon, verwijzersNaarTelefoonnummer, verwijzersNaarEmail);
            }

            if (checkUitgiftepunt == 0) {
                int maxVolgorde = getSQL.getCheckVolgordeLijst();
                excelSQL.insertUitgiftepunt(uitgiftepunt, maxVolgorde);
            }

            int Verwijzer2 = getSQL.getVerwijzernr(verwijzerNaam, verwijzersDoorContactpersoon);

            /// Wanneer er geen kaartnummer is die bekend gaat die door naar insert
            if (checkKaartnr == 0) {
                // Wanneer kaartnummer alles behalve 0 is insert die
                if (kaartnummer > 0) {
                    excelSQL.insertExcelClient(kaartnummer, naam, naamPartner, telefoonnummer, email, mobiel,
                            aantalPersonen, aantalPersonenInDeNorm, gebruikInMaanden, idSoort,
                            this.datumUitgifteId, idNummer, plaatsUitgifteId, adres, postcode, plaats, status,
                            pakketSoort, Verwijzer2);
                } else {
                    break;
                }
            } else {
                excelSQL.updateExcelClient(kaartnummer, naam, naamPartner, telefoonnummer, email, mobiel,
                        aantalPersonen, aantalPersonenInDeNorm, gebruikInMaanden, idSoort, this.datumUitgifteId,
                        idNummer, plaatsUitgifteId, adres, postcode, plaats, status, pakketSoort, Verwijzer2);
            }

            int checkIntake = getSQL.getCheckIntake(intakeDatum, startDatumUitgifte, datumHerintake,
                    kaartnummer);

            if (checkIntake == 0) {
                excelSQL.insertExcelIntake(intaker, intakeDatum, startDatumUitgifte, datumHerintake,
                        kaartnummer, uitgiftepunt);
                int intakeId = getSQL.getIntakeId(kaartnummer);
                excelSQL.insertExcelStopt(datumStopzetting, redenStopzetting, intakeId);
            }

            // Kan upgedate worden aan een knop voor een query aan status in de table voedselpakket wel of niet opgehaald
            String status1 = null;

            String checkStatus = getSQL.getStatus(kaartnummer);
            this.pakketAantal = getSQL.getPakketAantal(kaartnummer);
            int intakeId = getSQL.getIntakeId(kaartnummer);
            int checkPakket = getSQL.getPakket(this.excelDatum, intakeId);

            if (checkPakket == 0) {
                if (checkStatus != null) {
                    if (checkStatus.equals("Actief")) {
                        int intakeId2 = getSQL.getIntakeId(kaartnummer);
                        excelSQL.insertVoedselpakket(this.excelDatum, this.pakketAantal, status1, intakeId2,
                                uitgiftepunt);
                    }
                }
            }
        }
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:StateContentTest.java

/**
 * Reads the first sheet of the specified Excel spreadsheet into a Hashtable, 
 * where the value in the first column of each row is the Key and the following columns are added to a String[] of size columns
 * @param filename The name of the file to open including extension.
 * @param rows The number of rows to read.
 * @param columns The number of columns to read.
 * @param rowStart The row to start reading from.
 * @param colStart The column to start reading from.
 * @throws IOException/*w  w w. j a  va  2 s .  c  o m*/
 */
private void readExcel(String filename, int rows, int columns, int rowStart, int colStart) throws IOException {
    FileInputStream inputStream = new FileInputStream(new File("./data/" + filename));

    Workbook workbook = new XSSFWorkbook(inputStream);
    Sheet firstSheet = workbook.getSheetAt(0);
    Iterator<Row> iterator = firstSheet.iterator();
    iterator.next();
    iterator.next();

    for (int i = rowStart; i < rows; i++) {
        Row row = firstSheet.getRow(i);
        String[] copy = new String[columns];
        String stateName = "";
        for (int j = colStart; j < columns - 1; j++) {
            if (j == colStart)
                stateName = row.getCell(j).getStringCellValue();
            else
                copy[j] = row.getCell(j).getStringCellValue().replaceAll("\\u2022", "")
                        .replaceAll("(?m)^[ \t]*\r?\n", "").trim();
        }
        copyMatrix.put(stateName, copy);
    }

    workbook.close();
    inputStream.close();
}

From source file:ExampleClass.java

public static void main(String[] args) throws Exception {
    File src = new File(
            "C:\\Users\\Ariq\\Documents\\NetBeansProjects\\Skripsi-Jadwal-Mengawas-Ujian\\Contoh File\\Jadwal_Pengawas_ Ujian_Pak_ Pascal.xlsx");
    //File src = new File("D:\\\\Skripsi\\\\Data Baru\\\\Daftar Dosen.xlsx");
    FileInputStream fis = new FileInputStream(src);
    XSSFWorkbook wb = new XSSFWorkbook(fis);

    XSSFSheet sheet1 = wb.getSheetAt(0);
    //        Iterator< Row> rowIterator = sheet1.iterator();
    int colIndex = 0;
    int ex = 0;/*from w  w w  . java  2s .  c  o m*/
    int lastCol = sheet1.getLastRowNum();
    int i = 0;
    int idx = 0;
    CellRangeAddress add;

    //        while (rowIterator.hasNext()) {
    //            row = (XSSFRow) rowIterator.next();
    //            Iterator< Cell> cellIterator = row.cellIterator();
    //            //System.out.println("i = "+i+", ex:"+ex);
    //
    //            if (row.getRowNum() > 53) {
    //                break;
    //            }
    ////            if(lastCol-(ex+1) == i) break;
    //            while (cellIterator.hasNext()) {
    //                Cell cell = cellIterator.next();

    //                for (int f = 0; f < sheet1.getNumMergedRegions(); f++) {
    //                    add = sheet1.getMergedRegion(f);
    //                    
    //                    int col = add.getFirstColumn();
    //                    int rowNum = add.getFirstRow();
    //                    if (rowNum != 0 && rowNum == cell.getRowIndex() && colIndex == cell.getColumnIndex()) {
    //                        System.out.println("col:"+col+" "+",row :"+rowNum);
    //                        String b = String.valueOf(sheet1.getRow(rowNum).getCell(col));
    //                        System.out.println(b);     
    //                        
    //                    }
    //                    
    //                }
    //               switch (cell.getCellType()) 
    //               {
    //                  case Cell.CELL_TYPE_FORMULA:
    //                      ex++;
    //                       switch (cell.getCachedFormulaResultType()) 
    //                       {
    //                           case Cell.CELL_TYPE_NUMERIC:
    //                           i = (int)cell.getNumericCellValue();
    //                           System.out.print( 
    //                           (int)cell.getNumericCellValue() + " \t\t " );
    //                             
    //                                 
    //                           break;
    //                       }
    //                   break;
    //                  case Cell.CELL_TYPE_NUMERIC:
    //                    if (cell.getColumnIndex() >= 6)
    //                    {
    //                        System.out.print( 
    //                        (int)cell.getNumericCellValue() + " \t\t " );
    //                    }
    //                    break;
    //                  case Cell.CELL_TYPE_STRING:
    //                   add = sheet1.getMergedRegion(cell.getRowIndex());
    //              
    //                   if (cell.getStringCellValue().contentEquals("No."))
    //                    {
    //                       colIndex = cell.getColumnIndex();
    //                    }
    //                   if (cell.getColumnIndex() == 1)
    //                   {
    //                        System.out.print(
    //                        cell.getStringCellValue() + " \t\t " );
    //                   }              
    //                   break;
    //                  
    //               }
    //            }
    //
    //            System.out.println();
    //        }

    for (int j = 0; j < sheet1.getLastRowNum(); j++) {

        row = sheet1.getRow(j);
        for (int k = 0; k < row.getLastCellNum(); k++) {

            Cell cell = row.getCell(k);
            //                if (cell.getColumnIndex() == 1)
            //                {
            //                    System.out.println(cell.getStringCellValue());
            //                }
            FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
            if (cell.getColumnIndex() == 0 && j > 3
                    && evaluator.evaluate(cell).getCellType() != Cell.CELL_TYPE_NUMERIC) {
                System.exit(k);
            }
            if (cell.getColumnIndex() >= 6 && cell.getColumnIndex() <= 11) {
                if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    System.out.print((int) cell.getNumericCellValue() + " ");
                }
                if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    if (cell.getStringCellValue().contains(":")) {
                        String[] splt = cell.getStringCellValue().split(":");
                        String[] splt2 = splt[1].split(",");
                        for (int l = 0; l < splt2.length; l++) {
                            System.out.println(splt2[l] + "= lab");
                        }
                    }

                    else {
                        CellReference cr = new CellReference(1, cell.getColumnIndex());
                        Row row2 = sheet1.getRow(cr.getRow());
                        Cell c = row2.getCell(cr.getCol());
                        System.out.print(
                                cell.getStringCellValue() + " Ruang =" + (int) c.getNumericCellValue() + " ");
                    }

                }
                if (cell.getCellType() == Cell.CELL_TYPE_BLANK && cell.getRowIndex() > 2) {
                    CellReference cr = new CellReference(cell.getRowIndex() - 1, cell.getColumnIndex());
                    Row row2 = sheet1.getRow(cr.getRow());
                    Cell c = row2.getCell(cr.getCol());
                    CellReference cr2 = new CellReference(1, cell.getColumnIndex());
                    Row row3 = sheet1.getRow(cr2.getRow());
                    Cell c2 = row3.getCell(cr2.getCol());
                    if (c.getStringCellValue().contains(":")) {
                        String[] splt = c.getStringCellValue().split(":");
                        String[] splt2 = splt[1].split(",");
                        for (int l = 0; l < splt2.length; l++) {
                            System.out.println(splt2[l] + "= lab");
                        }
                    }

                    else {
                        System.out.print(
                                c.getStringCellValue() + " Ruang = " + (int) c2.getNumericCellValue() + " ");
                    }
                }
            }

        }
        System.out.println("");
    }
    System.out.println(colIndex);

    System.out.println(idx);

    fis.close();
}

From source file:SiteStatIndexer.java

License:Open Source License

private static XSSFWorkbook readFile(String filename) throws IOException {
    return new XSSFWorkbook(new FileInputStream(filename));
}

From source file:xlsxtocsv.java

static void convertToXlsx(File inputFile, File outputFile) {
    // For storing data into CSV files
    StringBuffer cellValue = new StringBuffer();
    try {/*  w w w . j a v a 2  s.c o  m*/
        FileOutputStream fos = new FileOutputStream(outputFile);

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

        // 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 + ",");

                }
            }

            cellValue.append("\n");
        }

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

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

From source file:ReadSheet2.java

public HashMap finalOutput(String path) throws IOException {

    FileInputStream fs = new FileInputStream(new File(path));
    XSSFWorkbook wb = new XSSFWorkbook(fs);
    XSSFSheet sheet = wb.getSheetAt(2);//  ww  w. ja  va  2  s  . c o m
    /*      Object [][] hardcodeValues = {{2,5,"SAMPLE TYPE"},{6,5,"EARLY COMPETION TIME"},{3,13,"Add. Cuts"}, {3,14,"Total"},{6,14,"SAMPLE PLAN END DATE & TIME"},
        {14,0,"Confirmation From Stores"},{14,10,"DATE",14,15,"TIME:"},{15,0,"Verification (G.Tech)"},{15,10,"DATE"},{15,15,"TIME:"},
        {17,0,"CUTTING TEAM :"},{17,15,"CUT DATE :"},{18,0,"CUTTER/S NAME :"},{18,15,"CUT TIME :"} ,
        {26,0,"CPI DONE BY :"},{26,16,"VERIFICATION DONE BY :"},{27,0,"COMMENTS :"},{27,16,"COMMENTS :"}};
    */
    System.out.println("---------------------------- Reading sheet2 -----------------------------------------");
    HashMap<String, Object> sheet2 = new HashMap();
    try {
        reader.hardCodeValidator(sheet, sheet2HardcodeValues);
    } catch (RuntimeException ex) {

    }

    try {
        sheet2.putAll(readTable1(path));
    } catch (RuntimeException ex) {

    }

    try {
        sheet2.putAll(readTable2(path));
    } catch (RuntimeException ex) {

    }
    try {
        sheet2.putAll(readTable3(path));
    } catch (RuntimeException ex) {

    }
    try {
        sheet2.putAll(readTable4(path));
    } catch (RuntimeException ex) {

    }

    System.out.println("Sheet 2 fully validated");
    return sheet2;
}

From source file:ReadSheet2.java

public HashMap readTable1(String path) throws IOException {

    HashMap<String, Object> table1part1 = new HashMap();
    HashMap<String, Object> table1part2 = new HashMap();
    HashMap<String, Object> table1 = new HashMap();
    HashMap<String, Object> sizeMetrix = new HashMap();
    FileInputStream fs = new FileInputStream(new File(path));
    XSSFWorkbook wb = new XSSFWorkbook(fs);
    XSSFSheet sheet = wb.getSheetAt(2);//from  w w  w . j  ava2 s.  co  m

    /*
    Read Table 1 of the sheet 1
    */

    //String [] headerArray1 = {"BUSINESS DIVISION","CUSTOMER NAME/CATEGORY","SEASON","STYLE NO","SAMPLE SMV"};
    //String [] headerArray2 = {"SILHOUETTE","MERCHANT NAME","GARMENT TECH NAME"};
    //int rowIndexOfHeaderStart, int columnIndexOfHeaders, String[] headerArray
    int[] rawHeaders = reader.rowHeaderValidator(sheet, 2, 0, sheet2Table1HeaderArray1);
    int[] rawheaders2 = reader.rowHeaderValidator(sheet, 2, 15, sheet2Table1HeaderArray2);
    //
    table1part1 = reader.readRowHeaderTable(sheet, 0, rawHeaders, 2, 2);
    table1part2 = reader.readRowHeaderTable(sheet, 15, rawheaders2, 17, 17);
    //table1.putAll(table1part1);
    //table1.putAll(table1part2);

    /** ----------------------------------------------------------------------------------------------------------------------- **/

    //String [] headerArray3 = {"QTY" };
    //String [] headerArray4 = {"XS","S","M","L","XL","XXL" };
    //int rowIndexOfHeaderStart, int columnIndexOfHeaders, String[] headerArray

    int[] rawheaders3 = reader.rowHeaderValidator(sheet, 3, 5, sheet2SizeMetrixRows);
    int[] columnHeaders4 = reader.columnHeaderValidator(sheet, 3, sheet2SizeMetrixColumns);

    //
    //int [] rawHeaders3={3,4};
    //int [] rawheaders4 ={5,7,8,9,10,11,12};

    table1part2 = reader.readColumnAndRowHeaderTable(sheet, 3, 7, columnHeaders4, 3, 4, rawheaders3);

    table1.put("cutting metrix", table1part2);

    table1.put(reader.getValue(sheet.getRow(3).getCell(13)).toString(),
            reader.getValue(sheet.getRow(4).getCell(13)));
    table1.put(reader.getValue(sheet.getRow(3).getCell(14)).toString(),
            reader.getValue(sheet.getRow(4).getCell(14)));

    table1.put(reader.getValue(sheet.getRow(2).getCell(5)).toString(),
            reader.getValue(sheet.getRow(5).getCell(7)));
    table1.put(reader.getValue(sheet.getRow(6).getCell(5)).toString(),
            reader.getValue(sheet.getRow(6).getCell(7)));
    table1.put(reader.getValue(sheet.getRow(6).getCell(14)).toString(),
            reader.getValue(sheet.getRow(6).getCell(17)));

    return table1;

}