Example usage for org.apache.poi.ss.usermodel Sheet getSheetName

List of usage examples for org.apache.poi.ss.usermodel Sheet getSheetName

Introduction

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

Prototype

String getSheetName();

Source Link

Document

Returns the name of this sheet

Usage

From source file:xmv.solutions.IT2JZ.Jira.Excel2TestcaseConverter.java

public List<JiraTestcase> parse() {

    // Reset first
    testcases = new ArrayList<JiraTestcase>();

    // Check Excel File
    if (excelFile == null || !excelFile.testExcelFile()) {
        return null;
    }//from   www.j  a v  a2  s .  c  om

    try {

        // Get the workbook instance for XLS file
        Workbook workbook = excelFile.getWorkbook();

        for (Sheet sheet : workbook) {

            String Sheetname = "";

            try {

                // Take Sheet next sheet
                Sheetname = sheet.getSheetName();

            } catch (Exception e) {

                // Problem with Excelfile
                break;
            }

            // Initiate TestSet
            String summary = null;
            String description = null;
            List<JiraTestcaseStep> steps = new ArrayList<JiraTestcaseStep>();
            JiraTestcaseStep step = null;

            for (Row row : sheet) {

                // Omitt first line or empty ones
                if (row.getRowNum() == 0 || row == null || row.getLastCellNum() < 1) {
                    continue;
                }

                try {

                    // Scan Columns
                    String A = row.getCell(0) != null ? row.getCell(0).getStringCellValue() : "";
                    String B = row.getCell(1) != null ? row.getCell(1).getStringCellValue() : "";
                    String C = row.getCell(2) != null ? row.getCell(2).getStringCellValue() : "";
                    String D = row.getCell(3) != null ? row.getCell(3).getStringCellValue() : "";
                    String E = row.getCell(4) != null ? row.getCell(4).getStringCellValue() : "";
                    String F = row.getCell(5) != null ? row.getCell(5).getStringCellValue() : "";

                    // if the First coulumn isn't empty, we start a new step
                    if (!A.isEmpty()) {

                        // finnish last testcase if we can, respctl all
                        // attributes are ready
                        if (summary != null && description != null && !steps.isEmpty()) {

                            // Generate testcase and add to List
                            testcases.add(new JiraTestcase(summary, description, steps));

                            // Reset
                            summary = null;
                            description = null;
                            step = null;
                            steps = new ArrayList<JiraTestcaseStep>();

                        }

                        // Start new Testcase
                        summary = parseMapping(summaryFM, A, B, C, D, E, F, Sheetname);
                        description = parseMapping(descriptionFM, A, B, C, D, E, F, Sheetname);
                        ;

                    }

                    step = new JiraTestcaseStep();
                    step.setStepName(parseMapping(testStepNameFM, A, B, C, D, E, F, Sheetname));
                    step.setTestData(parseMapping(testStepDataFM, A, B, C, D, E, F, Sheetname));
                    step.setExpectedResult(parseMapping(testStepExpectedResultFM, A, B, C, D, E, F, Sheetname));

                    steps.add(step);

                } catch (Exception e) {

                    e.printStackTrace();
                    break;

                }

            }

            // Generate very last testcase and add to List
            if (summary != null && description != null && !steps.isEmpty()) {
                testcases.add(new JiraTestcase(summary, description, steps));
            }

        }

    } catch (Exception e) {

        e.printStackTrace();

    }

    return testcases;

}