Example usage for org.apache.poi.xssf.usermodel XSSFSheet rowIterator

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet rowIterator

Introduction

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

Prototype

@Override
@SuppressWarnings("unchecked")
public Iterator<Row> rowIterator() 

Source Link

Usage

From source file:com.photon.phresco.framework.commons.FrameworkUtil.java

License:Apache License

private void writeTestCasesToXLSX(String testSuiteName, String[] cellValue, String status, int numCol,
        int cellno, CellStyle[] tryStyle, StringBuilder sb) throws PhrescoException {
    Iterator<Row> rowIterator;
    try {//w  w  w.  j  a va2s  . c om
        FileInputStream myInput = new FileInputStream(sb.toString());
        OPCPackage opc = OPCPackage.open(myInput);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(opc);
        int numberOfSheets = myWorkBook.getNumberOfSheets();
        for (int j = 0; j < numberOfSheets; j++) {
            XSSFSheet mySheet = myWorkBook.getSheetAt(j);
            if (mySheet.getSheetName().equals(testSuiteName)) {
                rowIterator = mySheet.rowIterator();
                Row next;
                for (Cell cell : mySheet.getRow((mySheet.getLastRowNum()) - 2)) {
                    tryStyle[cellno] = cell.getCellStyle();
                    cellno = cellno + 1;
                }
                float totalPass = 0;
                float totalFail = 0;
                float totalNotApp = 0;
                float totalBlocked = 0;
                float notExecuted = 0;
                float totalTestCases = 0;
                for (int i = 0; i <= 22; i++) {
                    rowIterator.next();
                }
                do {
                    next = rowIterator.next();
                    if (StringUtils.isNotEmpty(getValue(next.getCell(1)))
                            && !getValue(next.getCell(0)).equalsIgnoreCase("S.NO")) {
                        String value = getValue(next.getCell(11));
                        if (StringUtils.isNotEmpty(value)) {
                            if (value.equalsIgnoreCase("success")) {
                                totalPass = totalPass + 1;
                            } else if (value.equalsIgnoreCase("failure")) {
                                totalFail = totalFail + 1;
                            } else if (value.equalsIgnoreCase("notApplicable")) {
                                totalNotApp = totalNotApp + 1;
                            } else if (value.equalsIgnoreCase("blocked")) {
                                totalBlocked = totalBlocked + 1;
                            }
                        } else {
                            notExecuted = notExecuted + 1;
                        }
                    }
                } while (rowIterator.hasNext());
                //to update the status in the index page 
                if (status.equalsIgnoreCase("success")) {
                    totalPass = totalPass + 1;
                } else if (status.equalsIgnoreCase("failure")) {
                    totalFail = totalFail + 1;
                } else if (status.equalsIgnoreCase("notApplicable")) {
                    totalNotApp = totalNotApp + 1;
                } else if (status.equalsIgnoreCase("blocked")) {
                    totalBlocked = totalBlocked + 1;
                } else {
                    notExecuted = notExecuted + 1;
                }
                totalTestCases = totalPass + totalFail + totalNotApp + totalBlocked + notExecuted;
                XSSFSheet mySheet1 = myWorkBook.getSheetAt(0);
                rowIterator = mySheet1.rowIterator();
                for (int i = 0; i <= 2; i++) {
                    rowIterator.next();
                }
                while (rowIterator.hasNext()) {
                    Row next1 = rowIterator.next();
                    if (StringUtils.isNotEmpty(getValue(next1.getCell(2)))
                            && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) {
                        TestSuite createObject = createObject(next1);
                        if (createObject.getName().equals(testSuiteName)) {
                            addCalculationsToIndex(totalPass, totalFail, totalNotApp, totalBlocked, notExecuted,
                                    totalTestCases, next1);
                        }
                    }
                }

                Row r = null;
                if (mySheet.getSheetName().equalsIgnoreCase("Index")) {
                    r = mySheet.createRow(next.getRowNum() - 1);

                } else {
                    r = mySheet.createRow(next.getRowNum() + 1);
                }
                for (int i = 0; i < numCol; i++) {
                    Cell cell = r.createCell(i);
                    cell.setCellValue(cellValue[i]);

                    cell.setCellStyle(tryStyle[i]);
                }
                FileOutputStream fileOut = new FileOutputStream(sb.toString());
                myWorkBook.write(fileOut);
                myInput.close();
                fileOut.close();
            }

        }
    } catch (PhrescoException e) {
        throw new PhrescoException(e);
    } catch (IOException e) {
        throw new PhrescoException(e);
    } catch (InvalidFormatException e) {
        throw new PhrescoException(e);
    }
}

From source file:com.rknowsys.eapp.DataImportAction.java

/**
 * This method saves uploaded file into the server folder.And stores the
 * file data into the database./*from w ww .  ja v a 2s .c o m*/
 * 
 * @param actionRequest
 * @param actionResponse
 * @throws IOException
 */
public void saveDataImport(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException {
    System.out.println("saveDataImport method()..!!!!!!!!!!");
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    Properties properties = PortalUtil.getPortalProperties();
    String uploadDirectory = properties.getProperty("liferay.home") + "/data/uploadedFiles";
    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    byte[] bytes = null;

    try {
        // ==========Saving the uploaded file in server folder with uploaded
        // date and time as file filename prefix.===========

        Date date = new Date();
        SimpleDateFormat sd = new SimpleDateFormat("mm-dd-yyyy");
        String d = sd.format(date);
        System.out.println("uploaded date = " + d);
        File uploadedFile = uploadRequest.getFile("fileName");

        bytes = FileUtil.getBytes(uploadedFile);

        String fileName = uploadRequest.getFileName("fileName");
        File newFile = null;
        File newDirectory = new File(uploadDirectory);
        if (!newDirectory.exists()) {
            System.out.println("directory does not exist");
            Path directoryPath = Paths.get(uploadDirectory);
            Files.createDirectory(directoryPath.getParent());
        }
        newFile = new File(uploadDirectory + "/" + d + Calendar.getInstance().getTimeInMillis() + fileName);

        // ============Creating the New file in server folder===========

        if (!newFile.exists()) {
            System.out.println("file does not exist");
            Path pathToFile = Paths
                    .get(uploadDirectory + "/" + d + Calendar.getInstance().getTimeInMillis() + fileName);
            Files.createFile(pathToFile);

        }
        // =========Reading the uploaded file content and writing the
        // content to newly created file==============
        FileInputStream fileInputStream = new FileInputStream(uploadedFile);

        fileInputStream.read(bytes);
        FileOutputStream fileOutputStream = new FileOutputStream(newFile);
        fileOutputStream.write(bytes, 0, bytes.length);
        fileOutputStream.close();
        fileInputStream.close();

        String filePath = newFile.getAbsolutePath();
        System.out.println("filePath = " + filePath);

        FileInputStream file1 = new FileInputStream(new File(filePath));

        // Reading Excel file Rows and cells content using apache poi api
        // and saving the data in to the database.

        XSSFWorkbook workbook = new XSSFWorkbook(file1); // Create Workbook
        // instance
        // holding
        // reference to
        // .xlsx file

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

        @SuppressWarnings("rawtypes")
        Iterator rows = sheet.rowIterator(); // Iterate through each rows
        // one by one

        while (rows.hasNext()) {

            XSSFRow row = (XSSFRow) rows.next();
            if (row.getRowNum() != 0) {
                EmpPersonalDetails empPersonalDetails = EmpPersonalDetailsLocalServiceUtil
                        .createEmpPersonalDetails(CounterLocalServiceUtil.increment());
                Employee employee = EmployeeLocalServiceUtil
                        .createEmployee(CounterLocalServiceUtil.increment());
                JobTitle jobTitle = JobTitleLocalServiceUtil
                        .createJobTitle(CounterLocalServiceUtil.increment());
                SubUnit subUnit = SubUnitLocalServiceUtil.createSubUnit(CounterLocalServiceUtil.increment());
                EmploymentStatus employmentStatus = EmploymentStatusLocalServiceUtil
                        .createEmploymentStatus(CounterLocalServiceUtil.increment());
                EmpJob empJob = EmpJobLocalServiceUtil.createEmpJob(CounterLocalServiceUtil.increment());
                EmpSupervisor empSupervisor = EmpSupervisorLocalServiceUtil
                        .createEmpSupervisor(CounterLocalServiceUtil.increment());
                @SuppressWarnings("rawtypes")
                Iterator cells = row.cellIterator();

                while (cells.hasNext()) {

                    XSSFCell cell = (XSSFCell) cells.next();
                    if (cell.getColumnIndex() == 0) {
                        empPersonalDetails.setFirstName(cell.toString());
                    }
                    if (cell.getColumnIndex() == 1) {
                        empPersonalDetails.setMiddleName(cell.toString());
                    }
                    if (cell.getColumnIndex() == 2) {
                        empPersonalDetails.setLastName(cell.toString());
                    }
                    if (cell.getColumnIndex() == 3) {
                        empPersonalDetails.setEmployeeNo(cell.getRawValue());
                    }
                    if (cell.getColumnIndex() == 4) {
                        empPersonalDetails.setLicenseNo(cell.getRawValue());
                    }
                    if (cell.getColumnIndex() == 5) {
                        jobTitle.setTitle(cell.toString());
                    }
                    if (cell.getColumnIndex() == 6) {
                        employmentStatus.setEmploymentstatus(cell.toString());
                    }
                    if (cell.getColumnIndex() == 7) {
                        subUnit.setName(cell.toString());
                    }

                }
                employee.setUserId(themeDisplay.getUserId());
                employee.setGroupId(themeDisplay.getCompanyGroupId());
                employee.setCompanyId(themeDisplay.getCompanyId());
                employee.setCreateDate(date);
                employee.setModifiedDate(date);
                employee = EmployeeLocalServiceUtil.addEmployee(employee);

                empPersonalDetails.setUserId(themeDisplay.getUserId());
                empPersonalDetails.setGroupId(themeDisplay.getCompanyGroupId());
                empPersonalDetails.setCompanyId(themeDisplay.getCompanyId());
                empPersonalDetails.setCreateDate(date);
                empPersonalDetails.setModifiedDate(date);
                empPersonalDetails.setEmployeeId(employee.getEmployeeId());
                empPersonalDetails = EmpPersonalDetailsLocalServiceUtil
                        .addEmpPersonalDetails(empPersonalDetails);

                jobTitle.setUserId(themeDisplay.getUserId());
                jobTitle.setGroupId(themeDisplay.getCompanyGroupId());
                jobTitle.setCompanyId(themeDisplay.getCompanyId());
                jobTitle.setCreateDate(date);
                jobTitle.setModifiedDate(date);
                jobTitle = JobTitleLocalServiceUtil.addJobTitle(jobTitle);

                subUnit.setUserId(themeDisplay.getUserId());
                subUnit.setGroupId(themeDisplay.getCompanyGroupId());
                subUnit.setCompanyId(themeDisplay.getCompanyId());
                subUnit.setCreateDate(date);
                subUnit.setModifiedDate(date);
                subUnit = SubUnitLocalServiceUtil.addSubUnit(subUnit);

                employmentStatus.setUserId(themeDisplay.getUserId());
                employmentStatus.setGroupId(themeDisplay.getCompanyGroupId());
                employmentStatus.setCompanyId(themeDisplay.getCompanyId());
                employmentStatus.setCreateDate(date);
                employmentStatus.setModifiedDate(date);
                employmentStatus = EmploymentStatusLocalServiceUtil.addEmploymentStatus(employmentStatus);

                empJob.setJobTitleId(employee.getEmployeeId());
                empJob.setEmploymentStatusId(employmentStatus.getEmploymentStatusId());
                empJob.setSubUnitId(subUnit.getSubUnitId());
                empJob.setUserId(themeDisplay.getUserId());
                empJob.setGroupId(themeDisplay.getCompanyGroupId());
                empJob.setCompanyId(themeDisplay.getCompanyId());
                empJob.setCreateDate(date);
                empJob.setModifiedDate(date);
                empJob.setEmployeeId(employee.getEmployeeId());
                empJob = EmpJobLocalServiceUtil.addEmpJob(empJob);

                empSupervisor.setUserId(themeDisplay.getUserId());
                empSupervisor.setGroupId(themeDisplay.getCompanyGroupId());
                empSupervisor.setCompanyId(themeDisplay.getCompanyId());
                empSupervisor.setCreateDate(date);
                empSupervisor.setModifiedDate(date);
                empSupervisor.setEmployeeId(employee.getEmployeeId());
                empSupervisor.setReporterEmployeeId(empPersonalDetails.getEmployeeId());
                empSupervisor = EmpSupervisorLocalServiceUtil.addEmpSupervisor(empSupervisor);
            }

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

}

From source file:com.seer.datacruncher.fileupload.Excel_2007_FileReadObject.java

License:Open Source License

@Override
public String parseStream(long schemaId, InputStream ios) {
    List<SchemaFieldEntity> listSchemaFields = schemaFieldsDao.listSchemaFields(schemaId);
    StringBuffer sb = new StringBuffer();
    try {//from w  w w.  j  av  a2 s.  co m
        XSSFWorkbook myWorkBook = new XSSFWorkbook(ios);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator<Row> rowIter = mySheet.rowIterator();

        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

        while (rowIter.hasNext()) {
            int j = 0;
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator<Cell> cellIter = myRow.cellIterator();
            sb.append("<" + Tag.TAG_ROOT + ">");
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                String fieldValue = myCell.toString().trim();
                if (!listSchemaFields.get(j).getNillable() || fieldValue.length() > 0) {
                    sb.append("<" + listSchemaFields.get(j).getName() + ">")
                            .append(myCell.toString().replaceAll("&", "&amp;"))
                            .append("</" + listSchemaFields.get(j).getName() + ">");
                }
                j++;

                if (j == listSchemaFields.size() && cellIter.hasNext()) {
                    return I18n.getMessage("error.numberFieldsNoMatch");
                } else if (!cellIter.hasNext() && j != listSchemaFields.size()) {
                    return I18n.getMessage("error.numberFieldsNoMatch");
                }
            }
            sb.append("</" + Tag.TAG_ROOT + ">\n");
        }

    } catch (IOException e) {
        logger.error("Error occured during fetch records from excel file.", e);
        return "Could not able to parse Excel file. " + e.getMessage();
    }
    return sb.toString();
}

From source file:com.ts.control.UploadFile.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String campo1 = "";
    String campo2 = "";
    String campo3 = "";
    String campo4 = "";
    String campo5 = "";
    String campo6 = "";
    String campo7 = "";
    int c = 1;/*from   ww  w .  ja v a 2  s  . c o  m*/
    try {
        boolean ismultipart = ServletFileUpload.isMultipartContent(request);
        if (!ismultipart) {
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;
            try {
                items = upload.parseRequest(request);
            } catch (Exception e) {
            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                } else {
                    String itemname = item.getName();
                    if ((itemname == null || itemname.equals(""))) {
                        continue;
                    }
                    String filename = FilenameUtils.getName(itemname);
                    System.out.println("ruta---------------" + saveFile + filename);
                    File f = checkExist(filename);
                    item.write(f);
                    ////////
                    List cellDataList = new ArrayList();
                    try {
                        FileInputStream fileInputStream = new FileInputStream(f);
                        XSSFWorkbook workBook = new XSSFWorkbook(fileInputStream);
                        XSSFSheet hssfSheet = workBook.getSheetAt(0);
                        Iterator rowIterator = hssfSheet.rowIterator();
                        while (rowIterator.hasNext()) {
                            XSSFRow hssfRow = (XSSFRow) rowIterator.next();
                            Iterator iterator = hssfRow.cellIterator();
                            List cellTempList = new ArrayList();
                            while (iterator.hasNext()) {
                                XSSFCell hssfCell = (XSSFCell) iterator.next();
                                cellTempList.add(hssfCell);
                            }
                            cellDataList.add(cellTempList);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    out.println("<table border='3' class='table table-bordered table-striped table-hover'>");
                    for (int i = 1; i < cellDataList.size(); i++) {
                        List cellTempList = (List) cellDataList.get(i);
                        out.println("<tr>");
                        for (int j = 0; j < cellTempList.size(); j++) {
                            XSSFCell hssfCell = (XSSFCell) cellTempList.get(j);
                            String dato = hssfCell.toString();
                            out.print("<td>" + dato + "</td>");
                            switch (c) {
                            case 1:
                                campo1 = dato;
                                c++;
                                break;
                            case 2:
                                campo2 = dato;
                                c++;
                                break;
                            case 3:
                                campo3 = dato;
                                c++;
                                break;
                            case 4:
                                campo4 = dato;
                                c++;
                                break;
                            case 5:
                                campo5 = dato;
                                c++;
                                break;
                            case 6:
                                campo6 = dato;
                                c++;
                                break;
                            case 7:
                                campo7 = dato;
                                c = 1;
                                break;
                            }
                        }
                        //model.Consulta.addRegistros(campo1,campo2,campo3,campo4,campo5,campo6,campo7); 
                    }
                    out.println("</table><br>");
                    /////////
                }
            }
        }
    } catch (Exception e) {
    } finally {
        out.close();
    }
}

From source file:com.vsquaresystem.safedeals.amenity.AmenityService.java

public Vector read() throws IOException {
    File excelFile = attachmentUtils.getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.LOCATION);
    File[] listofFiles = excelFile.listFiles();
    String fileName = excelFile + "/" + listofFiles[0].getName();

    Vector cellVectorHolder = new Vector();
    int type;/*from www .  ja v  a2s.  c o  m*/
    try {
        FileInputStream myInput = new FileInputStream(fileName);

        XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();

            List list = new ArrayList();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                if (myCell != null) {
                    switch (myCell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:

                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_NUMERIC:

                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_STRING:

                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_ERROR:

                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        break;
                    }
                }
            }
            cellVectorHolder.addElement(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cellVectorHolder;

}

From source file:com.vsquaresystem.safedeals.location.LocationService.java

public Vector read() throws IOException {
    File excelFile = attachmentUtils.getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.LOCATION);
    File[] listofFiles = excelFile.listFiles();
    String fileName = excelFile + "/" + listofFiles[0].getName();
    Vector cellVectorHolder = new Vector();
    int type;//from w  w w . j  a v a2s. c  om
    try {
        FileInputStream myInput = new FileInputStream(fileName);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();
            List list = new ArrayList();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                if (myCell != null) {
                    switch (myCell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_STRING:
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_FORMULA:
                        break;
                    }
                }

            }

            cellVectorHolder.addElement(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cellVectorHolder;

}

From source file:com.vsquaresystem.safedeals.marketprice.MarketPriceService.java

public Vector read() throws IOException {

    File excelFile = attachmentUtils.getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.MARKET_PRICE);
    File[] listofFiles = excelFile.listFiles();
    String fileName = excelFile + "/" + listofFiles[0].getName();

    Vector cellVectorHolder = new Vector();
    int type;//  ww  w  . j av a  2s.  com
    try {
        FileInputStream myInput = new FileInputStream(fileName);

        XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();

            List list = new ArrayList();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                if (myCell != null) {
                    switch (myCell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_STRING:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        break;
                    }
                }

            }
            logger.info("Line Line108 {}" + list);
            System.out.println("MAINlist" + list);
            cellVectorHolder.addElement(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return cellVectorHolder;

}

From source file:com.vsquaresystem.safedeals.rawmarketprice.RawMarketPriceService.java

public Vector read() throws IOException {

    File excelFile = attachmentUtils
            .getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.RAW_MARKET_PRICE);
    File[] listofFiles = excelFile.listFiles();
    String fileName = excelFile + "/" + listofFiles[0].getName();

    Vector cellVectorHolder = new Vector();
    int type;//  ww  w  .  j  av  a 2  s . c o m
    try {
        FileInputStream myInput = new FileInputStream(fileName);

        XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();

            List list = new ArrayList();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                if (myCell != null) {
                    switch (myCell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_STRING:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        break;
                    }
                }

            }

            cellVectorHolder.addElement(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cellVectorHolder;

}

From source file:com.vsquaresystem.safedeals.readyreckoner.ReadyReckonerService.java

public Vector read() throws IOException {

    File excelFile = attachmentUtils
            .getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.READY_RECKONER);
    File[] listofFiles = excelFile.listFiles();
    String fileName = excelFile + "/" + listofFiles[0].getName();

    Vector cellVectorHolder = new Vector();
    int type;/*from  w  w w . j  a va 2  s.c o  m*/
    try {
        FileInputStream myInput = new FileInputStream(fileName);

        XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            XSSFRow myRow = (XSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();

            List list = new ArrayList();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();
                if (myCell != null) {
                    switch (myCell.getCellType()) {
                    case Cell.CELL_TYPE_BOOLEAN:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_STRING:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        System.out.println(new DataFormatter().formatCellValue(myCell));
                        list.add(new DataFormatter().formatCellValue(myCell));
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        break;
                    }
                }

            }
            cellVectorHolder.addElement(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return cellVectorHolder;

}

From source file:com.xhsoft.framework.common.file.ExcelHandle.java

License:Open Source License

/**
 * ????.xlsx// w  w  w  . ja  v  a 2 s.  c o m
 * @params {:,:}
 * @return void
 * @author lijiangwei
 * @since 2012-11-12
 */
private void readXLSX() {
    Iterator<XSSFSheet> sheets = xlsx.iterator();
    //??Sheet
    while (sheets.hasNext()) {
        XSSFSheet sheet = sheets.next();
        Iterator<Row> rows = sheet.rowIterator();
        //???Sheetrow
        while (rows.hasNext()) {
            XSSFRow row = (XSSFRow) rows.next();
            Iterator<Cell> cells = row.cellIterator();
            //???rowcell
            while (cells.hasNext()) {
                XSSFCell cell = (XSSFCell) cells.next();
                System.out.print("  " + getCellValue(cell));
            }
            System.out.println();
        }
    }
}