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

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

Introduction

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

Prototype

Cell getCell(int cellnum);

Source Link

Document

Get the cell representing a given column (logical cell) 0-based.

Usage

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

License:Apache License

private void updateTestCaseToXLSX(String fileName, com.photon.phresco.commons.model.TestCase tstCase,
        List<TestCase> testCases, StringBuilder sb) throws FileNotFoundException, InvalidFormatException,
        IOException, UnknownHostException, PhrescoException {
    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(fileName)) {
            Iterator<Row> rowIterator = mySheet.rowIterator();
            for (int i = 0; i <= 23; i++) {
                rowIterator.next();// w  ww.  j  a v  a2 s  . c  o m
            }
            while (rowIterator.hasNext()) {
                Row next = rowIterator.next();
                if (StringUtils.isNotEmpty(getValue(next.getCell(1)))) {
                    TestCase createObject = readTest(next);
                    testCases.add(createObject);
                    if (tstCase != null && createObject.getTestCaseId().equals(tstCase.getTestCaseId())) {

                        Cell preConditionsCell = next.getCell(5);
                        preConditionsCell.setCellValue(tstCase.getPreconditions());

                        Cell stepsCell = next.getCell(6);
                        stepsCell.setCellValue(tstCase.getSteps());

                        Cell expectedCell = next.getCell(9);
                        expectedCell.setCellValue(tstCase.getExpectedResult());

                        Cell actualCell = next.getCell(10);
                        actualCell.setCellValue(tstCase.getActualResult());

                        Cell statusCell = next.getCell(11);
                        statusCell.setCellValue(tstCase.getStatus());

                        Cell commentCell = next.getCell(12);
                        commentCell.setCellValue(tstCase.getBugComment());

                    }
                }

            }
            if (StringUtils.isNotEmpty(tstCase.getTestCaseId())) {
                float totalPass = 0;
                float totalFail = 0;
                float totalNotApplicable = 0;
                float totalBlocked = 0;
                for (TestCase testCase : testCases) {
                    String testCaseStatus = testCase.getStatus();
                    String testId = tstCase.getTestCaseId();
                    String status = tstCase.getStatus();
                    if (testCaseStatus.equalsIgnoreCase("success")
                            && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
                        totalPass = totalPass + 1;
                    } else if (testCaseStatus.equalsIgnoreCase("failure")
                            && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
                        totalFail = totalFail + 1;
                    } else if (testCaseStatus.equalsIgnoreCase("notApplicable")
                            && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
                        totalNotApplicable = totalNotApplicable + 1;
                    } else if (testCaseStatus.equalsIgnoreCase("blocked")
                            && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
                        totalBlocked = totalBlocked + 1;
                    }

                    if (testCase.getTestCaseId().equals(testId)
                            && !testCase.getStatus().equalsIgnoreCase("success")
                            && status.equalsIgnoreCase("success")) {
                        totalPass = totalPass + 1;
                    } else if (testCase.getTestCaseId().equals(testId)
                            && !testCase.getStatus().equalsIgnoreCase("failure")
                            && status.equalsIgnoreCase("failure")) {
                        totalFail = totalFail + 1;
                    } else if (testCase.getTestCaseId().equals(testId)
                            && !testCase.getStatus().equalsIgnoreCase("notApplicable")
                            && status.equalsIgnoreCase("notApplicable")) {
                        totalNotApplicable = totalNotApplicable + 1;
                    } else if (testCase.getTestCaseId().equals(testId)
                            && !testCase.getStatus().equalsIgnoreCase("blocked")
                            && status.equalsIgnoreCase("blocked")) {
                        totalBlocked = totalBlocked + 1;
                    }
                    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 (StringUtils.isNotEmpty(testId) && createObject.getName().equals(fileName)) {
                                updateIndex(totalPass, totalFail, totalNotApplicable, totalBlocked, next1, 0,
                                        "");
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotEmpty(tstCase.getTestCaseId())) {
                myInput.close();
                FileOutputStream outFile = new FileOutputStream(sb.toString());
                myWorkBook.write(outFile);
                outFile.close();
            }
        }
    }
}

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

License:Apache License

private void updateIndexPage(String fileName, com.photon.phresco.commons.model.TestCase tstCase,
        List<TestCase> testCases, HSSFWorkbook myWorkBook) throws UnknownHostException, PhrescoException {
    Iterator<Row> rowIterator;
    float totalPass = 0;
    float totalFail = 0;
    float totalNotApplicable = 0;
    float totalBlocked = 0;
    for (TestCase testCase : testCases) {
        String testCaseStatus = testCase.getStatus();
        String testId = tstCase.getTestCaseId();
        String status = tstCase.getStatus();
        if (testCaseStatus.equalsIgnoreCase("success") && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
            totalPass = totalPass + 1;/*from   www  .  j a  v  a  2 s  . c  om*/
        } else if (testCaseStatus.equalsIgnoreCase("failure")
                && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
            totalFail = totalFail + 1;
        } else if (testCaseStatus.equalsIgnoreCase("notApplicable")
                && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
            totalNotApplicable = totalNotApplicable + 1;
        } else if (testCaseStatus.equalsIgnoreCase("blocked")
                && !testCase.getTestCaseId().equalsIgnoreCase(testId)) {
            totalBlocked = totalBlocked + 1;
        }
        if (testCase.getTestCaseId().equalsIgnoreCase(testId)
                && !testCase.getStatus().equalsIgnoreCase("success") && status.equalsIgnoreCase("success")) {
            totalPass = totalPass + 1;
        } else if (testCase.getTestCaseId().equalsIgnoreCase(testId)
                && !testCase.getStatus().equalsIgnoreCase("failure") && status.equalsIgnoreCase("failure")) {
            totalFail = totalFail + 1;
        } else if (testCase.getTestCaseId().equalsIgnoreCase(testId)
                && !testCase.getStatus().equalsIgnoreCase("notApplicable")
                && status.equalsIgnoreCase("notApplicable")) {
            totalNotApplicable = totalNotApplicable + 1;
        } else if (testCase.getTestCaseId().equalsIgnoreCase(testId)
                && !testCase.getStatus().equalsIgnoreCase("blocked") && status.equalsIgnoreCase("blocked")) {
            totalBlocked = totalBlocked + 1;
        }
    }
    HSSFSheet 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 (StringUtils.isNotEmpty(tstCase.getTestCaseId()) && createObject.getName().equals(fileName)) {
                updateIndex(totalPass, totalFail, totalNotApplicable, totalBlocked, next1, 0, "");
            }
        }
    }
}