Example usage for org.apache.poi.hssf.usermodel HSSFCell toString

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell toString

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the cell This method returns a simple representation, anything more complex should be in user code, with knowledge of the semantics of the sheet being processed.

Usage

From source file:org.seasar.extension.dataset.impl.XlsReader.java

License:Apache License

/**
 * ????//from w  ww . j av a  2s  . co m
 * 
 * @param table
 *            
 * @param sheet
 *            
 */
protected void setupColumns(DataTable table, HSSFSheet sheet) {
    HSSFRow nameRow = sheet.getRow(0);
    HSSFRow valueRow = sheet.getRow(1);
    for (int i = 0; i <= Short.MAX_VALUE; ++i) {
        HSSFCell nameCell = nameRow.getCell((short) i);
        if (nameCell == null) {
            break;
        }
        String columnName = nameCell.getRichStringCellValue().getString();
        if (columnName.length() == 0) {
            break;
        }
        HSSFCell valueCell = null;
        if (valueRow != null) {
            for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                valueCell = sheet.getRow(j).getCell((short) i);
                if (valueCell != null && !StringUtil.isEmpty(valueCell.toString())) {
                    break;
                }
            }
        }
        if (valueCell != null) {
            table.addColumn(columnName, getColumnType(valueCell));
        } else {
            table.addColumn(columnName);
        }
    }
}

From source file:org.springframework.batch.spreadsheet.ExcelTemplate.java

License:Apache License

/**
 * This is the core method, and used when the user needs to override the number of steps
 * to take in searching for the cell.//from   ww w .ja  va 2  s. c o m
 * 
 * TODO: Test this.
 * 
 * @param sheet
 * @param keyPhrase
 * @param maxSteps
 * @return
 */
private Point searchForCell(HSSFSheet sheet, String keyPhrase, int maxSteps) {
    int row = 0;
    int column = 0;
    Direction parseDirection = Direction.TRANSITION_DOWN;
    int steps = 0;
    while (steps < maxSteps) {
        HSSFCell cell = sheet.getRow(row).getCell(column);
        if (cell != null) {
            if (cell.toString().equals(keyPhrase)) {
                return new Point(column, row);
            }
        }
        switch (parseDirection) {
        case GOING_DOWN:
            row++;
            column--;
            steps++;
            if (column == 0)
                parseDirection = Direction.TRANSITION_DOWN;
            break;
        case GOING_UP:
            row--;
            column++;
            steps++;
            if (row == 0)
                parseDirection = Direction.TRANSITION_ACROSS;
            break;
        case TRANSITION_DOWN:
            row++;
            steps++;
            parseDirection = Direction.GOING_UP;
            break;
        case TRANSITION_ACROSS:
            column++;
            steps++;
            parseDirection = Direction.GOING_DOWN;
            break;
        }
    }
    throw new RuntimeException("Could not find '" + keyPhrase + "' in less than " + maxSteps + " steps.");
}

From source file:phoenixplcscadahelper.AnaEkran.java

private void dosyaSecButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dosyaSecButtonActionPerformed
    opcName = getOpcName();/*  ww  w.ja  v  a 2 s  . co  m*/
    modbusMasterName = getModbusName();
    opcNameLabel.setText("OPC Ad = " + opcName);
    visuOpcTextArea.setText("");
    visuVarTextArea.setText("");

    JFileChooser jfc = new JFileChooser();
    jfc.setDialogTitle("Ltfen IO Liste Dosyas Sein");
    jfc.setCurrentDirectory(new java.io.File("."));
    jfc.setFileFilter(new FileNameExtensionFilter("Excel Files", "xls"));
    int returnVal = jfc.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File xlsFile = jfc.getSelectedFile();

        //..
        java.io.FileInputStream file;
        try {
            file = new java.io.FileInputStream(xlsFile);
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheetAt(0);
            int maxRowNr = sheet.getLastRowNum();
            digitalTagCount = 0;
            modbusInNr = 1000;
            modbusOutNr = 0;

            // esa tag dosyas
            esaWb = new HSSFWorkbook();
            fillEsaWb();

            // esa alarm dosyas
            esaAWb = new HSSFWorkbook();
            fillEsaAWb();

            // esa analog tag dosyas
            esaAnalogWb = new HSSFWorkbook();
            fillEsaAnalogWb();

            for (int i = 0; i < maxRowNr; i++) {

                if (sheet.getRow(i) == null) {
                } else if (sheet.getRow(i).getCell(3) == null) {
                } else {
                    HSSFCell cell = sheet.getRow(i).getCell(3);
                    if (cell.toString().startsWith("O")) { //DIGITAL OUTPUT
                        digitalOutput(sheet.getRow(i));
                    }
                    if (cell.toString().startsWith("I")) { //DIGITAL INPUT
                        digitalInput(sheet.getRow(i));
                    }
                    if (cell.toString().startsWith("AI")) { //ANALOG INPUT
                        analogInput(sheet.getRow(i));
                    }
                    if (cell.toString().startsWith("AO")) { //ANALOG OUTPUT
                        analogOutput(sheet.getRow(i));
                    }
                }
            }

            FileOutputStream fileOut = new FileOutputStream(xlsFile.getParent() + "\\esaTag.xls");
            esaWb.write(fileOut);
            fileOut.close();
            FileOutputStream fileAOut = new FileOutputStream(xlsFile.getParent() + "\\esaAlarms.xls");
            esaAWb.write(fileAOut);
            fileAOut.close();
            FileOutputStream fileAnalogOut = new FileOutputStream(xlsFile.getParent() + "\\esaAnalogTag.xls");
            esaAnalogWb.write(fileAnalogOut);
            fileAnalogOut.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(AnaEkran.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(AnaEkran.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:QuickExcel.ExcelData.java

public void loadData() {
    try {// w  ww  .  jav  a 2s.  c  o m
        File file = new File("excel.xls");
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell cell;

        int rows; // No of rows
        rows = sheet.getPhysicalNumberOfRows();

        int cols = 0; // No of columns
        int tmp = 0;

        // This trick ensures that we get the data properly even if it doesn't start from first few rows
        for (int i = 0; i < 10 || i < rows; i++) {
            row = sheet.getRow(i);
            if (row != null) {
                tmp = sheet.getRow(i).getPhysicalNumberOfCells();
                if (tmp > cols) {
                    cols = tmp;
                }
            }
        }

        for (int r = 0; r < rows; r++) {
            row = sheet.getRow(r);
            if (row != null) {
                for (int c = 0; c < 2; c++) {
                    cell = row.getCell(c);
                    if (c == 0) {
                        if (cell != null) {
                            addQuestion(cell.toString());
                        }

                    } else {
                        if (cell != null) {
                            addAnswer(cell.toString());
                        }

                    }
                }
            }
        }
    } catch (Exception ioe) {
        ioe.printStackTrace();
    }
}

From source file:swift.selenium.ExcelUtility.java

License:Open Source License

public static Reporter CompareExcel(HSSFSheet actualSheet, HSSFSheet expectedSheet, List<String> columns,
        List<String> columnsData, String testCaseID, String transactionType, int actualSheetRowCount)
        throws IOException {
    boolean isrowFound = false;
    int expSheetRowCount = getRowCount(expectedSheet); //expectedSheet.getPhysicalNumberOfRows();
    Reporter report = new Reporter();
    report.setReport(report);/* w w  w . j av a  2  s .  co  m*/
    int passCount = 0, failCount = 0, colCount = 0, finalRowCount = 0;

    //TM-28/09/2015: if expected sheet row count is greater than actual sheet row count than comparison should be on basis of expected sheet row count else vice-versa
    if (expSheetRowCount >= actualSheetRowCount)
        finalRowCount = expSheetRowCount;
    else
        finalRowCount = actualSheetRowCount;

    for (int rowIndex = firstRow; rowIndex < firstRow + finalRowCount; rowIndex++) {
        passCount = 0;
        failCount = 0;
        int currentRow = ++WebVerification.currentRowIndex;
        HSSFRow actualRow = actualSheet.getRow(currentRow);
        HSSFRow expectedRow = expectedSheet.getRow(rowIndex);

        //TM-28/09/2015: if actual and expected sheet row count does not match then break after following the steps in this code block.
        if (actualRow == null || expectedRow == null) {
            status.clear();
            report.strStatus = "FAIL";
            report.setStrStatus(report.strStatus);
            rowStatus.add(report.strStatus);
            failCount += 1;

            //TM-28/09/2015: if expected sheet row count is greater than actual sheet row count else vice-versa
            if (actualRow == null)
                report.strActualValue = "Expected No. of rows are greater than Actual No. of rows.";
            else
                report.strActualValue = "Actual No. of rows are greater than Expected No. of rows.";

            actualValue = new ArrayList<String>();
            actualValue.add(report.strActualValue);
            actualRows.add(actualValue);
            PassCount.add(passCount);
            FailCount.add(failCount);
            report.setReport(report);
            break;
        }

        if (actualRow.getCell(0).toString().equals(expectedRow.getCell(0).toString())
                && actualRow.getCell(1).toString().equals(expectedRow.getCell(1).toString())) {

            isrowFound = true;
            actualValue = new ArrayList<String>();

            //TM:6/08/15-This is unreachable code
            /*if(actualRow == null || expectedRow == null)
            {
               break;
            }*/

            colCount = expectedRow.getPhysicalNumberOfCells();
            for (int columnIndex = 3; columnIndex < colCount; columnIndex++) {
                HSSFCell actualCell = actualRow.getCell(columnIndex);
                DataFormatter fmt = new DataFormatter();
                HSSFCell expectedCell = expectedRow.getCell(columnIndex);
                //TM: commented the code to find replacement of continue
                /*if(actualCell == null || expectedCell == null)
                {
                   continue;
                }*/
                //TM: Following 'if' is replacement of the above
                if (actualCell != null || expectedCell != null) {
                    String expectedValue = fmt.formatCellValue(expectedCell);

                    if (!actualCell.toString().equalsIgnoreCase(expectedValue)) {
                        report.strStatus = "FAIL";
                        report.setStrStatus(report.strStatus);
                        failCount += 1;
                        report.strActualValue = "FAIL |" + expectedValue + "|" + actualCell.toString();
                    } else {
                        passCount += 1;
                        report.strStatus = "PASS";
                        report.setStrStatus(report.strStatus);
                        report.strActualValue = actualCell.toString();
                        //System.out.println(actualCell.toString());
                    }
                    status.add(report.strStatus);
                    actualValue.add(report.strActualValue);
                }

            }
            if (status.contains("FAIL")) {
                report.strStatus = "FAIL";
            } else {
                report.strStatus = "PASS";
            }
            status.clear();
            rowStatus.add(report.strStatus);
            PassCount.add(passCount);
            FailCount.add(failCount);
            actualRows.add(actualValue);
            report.setReport(report);
        } else if (isrowFound == false) {
            continue;
            /*MainController.pauseFun("No Rows Found For Comparision");
            break;*/
        }
    }
    if (rowStatus.contains("FAIL")) {
        report.strStatus = "FAIL";
    }
    WriteToDetailResults(testCaseID, transactionType, columns, actualRows, passCount, failCount,
            expSheetRowCount, colCount, report, rowStatus);
    PassCount.clear();
    FailCount.clear();
    return report;
}

From source file:swift.selenium.ExcelUtility.java

License:Open Source License

public static Reporter CompareExcelRowWise(HSSFSheet actualSheet, HSSFSheet expectedSheet, List<String> columns,
        List<String> columnsData, String testCaseID, String transactionType) throws IOException {
    boolean isrowFound = false;

    int expSheetRowCount = getRowCount(expectedSheet);//expectedSheet.getPhysicalNumberOfRows(); 
    int effectivefirstRow = firstRow;
    int actualSheetRowCount = ExcelUtility.getRowCount(actualSheet);
    Reporter report = new Reporter();
    report.setReport(report);//from  www  . j  av a 2 s. c  om
    int passCount = 0, failCount = 0, colCount = 0, finalRowCount = 0;
    WebVerification.currentRowIndex = 0;

    //TM-28/09/2015: if expected sheet row count not matching actual sheet row count than Come out
    if (expSheetRowCount != actualSheetRowCount) {
        TransactionMapping.report.strStatus = "FAIL";
        TransactionMapping.report.strMessage = "Expected No. of rows does not match Actual No. of rows, Please check Expected and Actual sheets";

    }

    else {

        for (int rowIndex = effectivefirstRow; rowIndex < effectivefirstRow + expSheetRowCount; rowIndex++) {
            passCount = 0;
            failCount = 0;
            int currentRow = ++WebVerification.currentRowIndex;
            HSSFRow actualRow = actualSheet.getRow(currentRow);
            HSSFRow expectedRow = expectedSheet.getRow(rowIndex);

            //TM-28/09/2015: if actual and expected sheet row count does not match then break after following the steps in this code block.
            if (actualRow == null || expectedRow == null) {
                status.clear();
                report.strStatus = "FAIL";
                report.setStrStatus(report.strStatus);
                rowStatus.add(report.strStatus);
                failCount += 1;

                //TM-28/09/2015: if expected sheet row count is greater than actual sheet row count else vice-versa
                if (actualRow == null)
                    report.strActualValue = "Expected No. of rows are greater than Actual No. of rows.";
                else
                    report.strActualValue = "Actual No. of rows are greater than Expected No. of rows.";

                actualValue = new ArrayList<String>();
                actualValue.add(report.strActualValue);
                actualRows.add(actualValue);
                PassCount.add(passCount);
                FailCount.add(failCount);
                report.setReport(report);
                break;
            }

            if (actualRow.getCell(0).toString().equals(expectedRow.getCell(0).toString())
                    && actualRow.getCell(1).toString().equals(expectedRow.getCell(1).toString())) {

                isrowFound = true;
                actualValue = new ArrayList<String>();

                colCount = expectedRow.getPhysicalNumberOfCells();
                for (int columnIndex = 3; columnIndex < colCount; columnIndex++) {
                    HSSFCell actualCell = actualRow.getCell(columnIndex);
                    DataFormatter fmt = new DataFormatter();
                    HSSFCell expectedCell = expectedRow.getCell(columnIndex);

                    //TM: Following 'if' is replacement of the above
                    if (actualCell != null || expectedCell != null) {
                        String expectedValue = fmt.formatCellValue(expectedCell);

                        if (!actualCell.toString().equalsIgnoreCase(expectedValue)) {
                            report.strStatus = "FAIL";
                            report.setStrStatus(report.strStatus);
                            failCount += 1;
                            report.strActualValue = "FAIL |" + expectedValue + "|" + actualCell.toString();
                        } else {
                            passCount += 1;
                            report.strStatus = "PASS";
                            report.setStrStatus(report.strStatus);
                            report.strActualValue = actualCell.toString();
                            System.out.println(actualCell.toString());
                        }
                        status.add(report.strStatus);
                        actualValue.add(report.strActualValue);
                    }

                }
                if (status.contains("FAIL")) {
                    report.strStatus = "FAIL";
                    TransactionMapping.report.strStatus = "FAIL";
                    TransactionMapping.report.strMessage = "Please refer to Detailed Results for more info..";
                } else {
                    report.strStatus = "PASS";
                }
                status.clear();
                rowStatus.add(report.strStatus);
                PassCount.add(passCount);
                FailCount.add(failCount);
                actualRows.add(actualValue);
                report.setReport(report);
            } else if (isrowFound == false) {
                continue;
            }
        }
        if (rowStatus.contains("FAIL")) {
            report.strStatus = "FAIL";
        }
        WriteToDetailResults(testCaseID, transactionType, columns, actualRows, passCount, failCount,
                expSheetRowCount, colCount, report, rowStatus);
    }

    PassCount.clear();
    FailCount.clear();
    return report;
}

From source file:swift.selenium.MainController.java

License:Open Source License

/**Finds the Start Pointer in the MainController Sheet and executes the Transaction**/
public static Reporter ControllerData(String FilePath) throws Exception {

    Reporter report = new Reporter();
    HSSFSheet reqSheet = ExcelUtility.GetSheet(Automation.configHashMap.get("CONTROLLER_FILEPATH").toString(),
            "MainControlSheet");
    sheetValues = WebHelper.getValueFromHashMap(reqSheet);
    int execFlag = Integer.parseInt(sheetValues.get("ExecuteFlag").toString());
    int rowCount = reqSheet.getLastRowNum() + 1;
    int colCount = 0;
    boolean isStartFound = false;

    for (int rowindex = 0; rowindex < rowCount && !isStartFound; rowindex++) {
        controllerRow = reqSheet.getRow(rowindex);
        //TM: commented the following to avoid continue
        /*if(controllerRow.getCell(execFlag).toString().equals(null))
        {//  ww  w  . j  a  v  a  2 s .  c om
           continue;
        }*/
        //TM: following 'if' is replacement of the above
        if (controllerRow.getCell(execFlag) != null) {
            if (controllerRow.getCell(execFlag).toString().equals("Y")) {
                colCount = controllerRow.getLastCellNum() + 1;
                for (int colIndex = execFlag + 1; colIndex < colCount; colIndex++) {
                    HSSFCell cellVal = controllerRow.getCell(colIndex);

                    //TM: commented the following code to avoid continue
                    /*if(cellVal == null)
                    {
                       System.out.println("START not Found");
                       continue;
                            
                    }
                    else */
                    //TM: following new if added to check for null and else part for the same.
                    if (cellVal != null) {
                        if (cellVal.toString().equalsIgnoreCase("START")) {
                            startCol = colIndex;
                            startRow = rowindex;
                            isStartFound = true;
                            break;

                        }
                    } else {
                        System.out.println("START not Found");
                    }

                }
            } else {
                System.out.println("Execute Flag is N");
            }
        }

    }

    for (int rowIndex = startRow; rowIndex < rowCount; rowIndex++) {
        pauseExecution = false;
        controllerRow = reqSheet.getRow(rowIndex);
        colCount = controllerRow.getLastCellNum() + 1;
        testDesciption = WebHelper.getCellData("Test_Description", reqSheet, rowIndex, sheetValues);
        HSSFCell executeFlag = controllerRow.getCell(execFlag);
        controllerTestCaseID = controllerRow
                .getCell(Integer.parseInt(sheetValues.get("TestCaseID").toString()));
        controllerGroupName = controllerRow.getCell(Integer.parseInt(sheetValues.get("GroupName").toString()));

        if (controllerTestCaseID.getStringCellValue().equalsIgnoreCase("")
                || controllerTestCaseID.equals(null)) {
            System.out.println("No KeyWord Found");
            continue;
        }

        //TM: Commented the code to avoid continue
        /*if(executeFlag == null)
        {
           System.out.println("Execute Flag is not Set");
           continue;
        }*/

        if (executeFlag != null) {
            if (executeFlag.toString().equalsIgnoreCase("Y")) {
                for (int columnIndex = startCol + 1; columnIndex < colCount && !pauseExecution; columnIndex++) {
                    controllerTransactionType = controllerRow.getCell(columnIndex);
                    //TM: commented the following code to avoid continue
                    /*if(controllerTransactionType == null || controllerTransactionType.getStringCellValue().equals(""))
                    {
                       System.out.println("No Transaction Found in the Maincontroller at Cell : "+columnIndex);
                       continue;
                    }*/

                    //TM: Updated following sysout to give an understanding of what is getting printed on the console
                    System.out.println("Value of controllerTransactionType: " + controllerTransactionType);

                    //TM: wrapped the PAUSE if into another if as replacement of above commented if
                    if (controllerTransactionType != null
                            && StringUtils.isNotBlank(controllerTransactionType.getStringCellValue())) {
                        if (controllerTransactionType.toString().equalsIgnoreCase("PAUSE")) {
                            TransactionMapping.pauseFun("Do You Wish To Continue");
                        } else {
                            report = TransactionMapping.TransactionInputData(
                                    controllerTransactionType.getStringCellValue(),
                                    controllerTestCaseID.getStringCellValue(), testDesciption,
                                    controllerGroupName.getStringCellValue());
                        }
                    } else {
                        System.out
                                .println("No Transaction Found in the Maincontroller at Cell : " + columnIndex);
                    }

                }
            }
        } else {
            System.out.println("Execute Flag is not Set");
        }

    }
    startCol = execFlag + 1;

    return report;
}

From source file:SwiftSeleniumWeb.MainController.java

License:Open Source License

/**
 * Finds the Start Pointer in the MainController Sheet and executes the Transaction
 * /*from  w  w  w . j a  v  a  2s  . c o m*/
 * @param FilePath
 * @return
 * @throws Exception
 */
public static Reporter ControllerData(String FilePath) throws Exception {
    Reporter report = new Reporter();
    HSSFSheet reqSheet = ExcelUtility.GetSheet(Automation.configHashMap.get("CONTROLLER_FILEPATH").toString(),
            "MainControlSheet");
    sheetValues = WebHelper.getValueFromHashMap(reqSheet);
    int execFlag = Integer.parseInt(sheetValues.get("ExecuteFlag").toString());
    int rowCount = reqSheet.getLastRowNum() + 1;
    int colCount = 0;
    boolean isStartFound = false;
    for (int rowindex = 0; rowindex < rowCount && !isStartFound; rowindex++) {
        controllerRow = reqSheet.getRow(rowindex);

        if (controllerRow.getCell(execFlag) != null) {
            if (controllerRow.getCell(execFlag).toString().equals("Y")) {
                colCount = controllerRow.getLastCellNum() + 1;
                for (int colIndex = execFlag + 1; colIndex < colCount; colIndex++) {
                    HSSFCell cellVal = controllerRow.getCell(colIndex);

                    if (cellVal != null) {
                        if (cellVal.toString().equalsIgnoreCase("START")) {
                            startCol = colIndex;
                            startRow = rowindex;
                            isStartFound = true;
                            break;

                        }
                    } else {
                        System.out.println("START not Found");
                    }

                }
            } else {
                System.out.println("Execute Flag is N");
            }
        }

    }

    for (int rowIndex = startRow; rowIndex < rowCount; rowIndex++) {
        pauseExecution = false;
        controllerRow = reqSheet.getRow(rowIndex);
        colCount = controllerRow.getLastCellNum() + 1;
        testDesciption = WebHelper.getCellData("Test_Description", reqSheet, rowIndex, sheetValues);
        HSSFCell executeFlag = controllerRow.getCell(execFlag);
        controllerTestCaseID = controllerRow
                .getCell(Integer.parseInt(sheetValues.get("TestCaseID").toString()));
        controllerGroupName = controllerRow.getCell(Integer.parseInt(sheetValues.get("GroupName").toString()));

        if (controllerTestCaseID.getStringCellValue().equalsIgnoreCase("")
                || controllerTestCaseID.equals(null)) {
            System.out.println("No KeyWord Found");
            continue;
        }

        if (executeFlag != null) {
            if (executeFlag.toString().equalsIgnoreCase("Y")) {
                for (int columnIndex = startCol + 1; columnIndex < colCount && !pauseExecution; columnIndex++) {
                    controllerTransactionType = controllerRow.getCell(columnIndex);

                    System.out.println("Value of controllerTransactionType: " + controllerTransactionType);

                    if (controllerTransactionType != null
                            && StringUtils.isNotBlank(controllerTransactionType.getStringCellValue())) {
                        if (controllerTransactionType.toString().equalsIgnoreCase("PAUSE")) {
                            pauseFun("Do You Wish To Continue");
                        } else {
                            report = TransactionMapping.TransactionInputData(controllerTestCaseID,
                                    controllerTransactionType,
                                    Automation.configHashMap.get("TRANSACTION_INPUT_FILEPATH").toString());
                        }
                    } else {
                        System.out
                                .println("No Transaction Found in the Maincontroller at Cell : " + columnIndex);
                    }

                }
            }
        } else {
            System.out.println("Execute Flag is not Set");
        }

    }
    startCol = execFlag + 1;
    return report;
}

From source file:SwiftSeleniumWeb.TransactionMapping.java

License:Open Source License

public static Reporter TransactionInputData(HSSFCell controllerTestCaseID, HSSFCell controllertransactionType,
        String filePath) throws Exception {
    Reporter report = new Reporter();
    HashMap<String, Object> inputHashTable = new HashMap<String, Object>();
    HSSFSheet workSheet = ExcelUtility.GetSheet(
            Automation.configHashMap.get("TRANSACTION_INPUT_FILEPATH").toString(),
            "Web_Transaction_Input_Files");
    int rowCount = workSheet.getLastRowNum() + 1;
    for (int rowIndex = 1; rowIndex < rowCount && !MainController.pauseExecution; rowIndex++) {
        String transactionCode = WebHelper.getCellData("TransactionCode", workSheet, rowIndex, inputHashTable);
        String transactionType = WebHelper.getCellData("TransactionType", workSheet, rowIndex, inputHashTable);
        String directoryPath = WebHelper.getCellData("DirPath", workSheet, rowIndex, inputHashTable).toString();//
        String inputExcel = WebHelper.getCellData("InputSheet", workSheet, rowIndex, inputHashTable).toString();
        if (transactionType.toString().equalsIgnoreCase(controllertransactionType.toString())) {
            if (transactionCode != null && directoryPath == null
                    && controllertransactionType.toString().equalsIgnoreCase(transactionType.toString())) {
                report.strInputPath = "";
                report.strOperationType = "";
                report.strTransactioncode = transactionCode;
                WebDriver.DataInput("", controllerTestCaseID.toString(), transactionType, transactionCode, "");
                break;
            }/*from  w ww.ja  v  a2s  .c  om*/

            if (!transactionType.toString().startsWith("Verify")) {
                operationType = "Input";
            }

            if (transactionType.toString().startsWith("Verify") && (!directoryPath.toString().isEmpty())
                    && (!inputExcel.toString().isEmpty())) {
                operationType = "InputandVerfiy";

            } else if (transactionType.toString().startsWith("Verify") && (directoryPath.toString().isEmpty())
                    && (inputExcel.toString().isEmpty())) {
                operationType = "Verify";
            }
            if (controllertransactionType.toString().equalsIgnoreCase(transactionType.toString())) {
                if ((directoryPath == null || inputExcel == null) && operationType != "Verify") {
                    MainController.pauseFun("Please Enter the directory or excelsheet name");
                } else {
                    String inputFilePath = null;
                    if (operationType != "Verify") {
                        inputFilePath = Automation.configHashMap.get("INPUT_DATA_FILEPATH").toString()
                                + directoryPath.toString() + "\\" + inputExcel.toString();
                    }
                    System.out.println(inputFilePath);
                    report.strInputPath = inputFilePath;
                    report.strOperationType = operationType;
                    report.strTransactioncode = transactionCode;
                    WebDriver.DataInput(inputFilePath, controllerTestCaseID.toString(), transactionType,
                            transactionCode, operationType);
                    break;
                }
            }
        } else if (!transactionType.toString().equalsIgnoreCase(controllertransactionType.toString())
                && rowIndex == rowCount - 1) {
            MainController.pauseFun(
                    "Transaction " + MainController.controllerTransactionType.toString() + " Not Found");
            ExcelUtility.writeReport(SwiftSeleniumWeb.WebDriver.report);
        }
    }
    return null;
}

From source file:test.gov.nih.nci.cacoresdk.PropertyGenerator.java

License:BSD License

@SuppressWarnings("deprecation")
public void generateConfigurationFiles(String confFileName, String outputDir) throws Exception {
    InputStream configFile = new FileInputStream(confFileName);
    HSSFWorkbook wb = new HSSFWorkbook(configFile);
    HSSFSheet sheet = wb.getSheetAt(0);/*from   w w w  . j  av a  2 s  .co  m*/
    int rowNum = sheet.getLastRowNum();
    HSSFRow row = sheet.getRow(0);
    int colNum = row.getLastCellNum();

    ArrayList<String> names = new ArrayList<String>();
    for (int i = 0; i < colNum; i++) {
        HSSFCell currentCell = row.getCell(i);
        if (currentCell == null) {
            names.add("");
        } else {
            currentCell.setCellType(currentCell.CELL_TYPE_STRING);
            names.add(currentCell.toString());
        }
    }
    /*
     * First Line includes names for all different configurations   (Requirement 1)
     * Second column is the default value  (Requirement 2)
     * From 3 - colNum are names of different configurations. (Requirement 3) 
     */

    int currentRowNum = 1;

    /*
     * Loop through xls file to generate properties files
     */

    while (currentRowNum <= rowNum && countRow(sheet.getRow(currentRowNum++)) == 1) {
        ArrayList<String> propertiesNames = new ArrayList<String>();

        String filename = getFirstString(sheet.getRow(currentRowNum - 1));

        int rowCount = 0;
        int headerRow = currentRowNum - 1;
        while (currentRowNum <= rowNum && countRow(sheet.getRow(currentRowNum++)) != 1) {
            rowCount++;
        }

        ArrayList<Properties> properties = new ArrayList<Properties>();
        properties.add(new Properties());
        for (int i = 1; i < colNum; i++) {
            Properties prop = new Properties();
            properties.add(prop);
        }

        currentRowNum = headerRow + 1;
        for (int i = currentRowNum; i < currentRowNum + rowCount; i++) {
            HSSFRow currentRow = sheet.getRow(i);
            if (currentRow == null)
                continue;
            if (currentRow.getCell(0) == null)
                continue;
            String propertyName = currentRow.getCell(0).getStringCellValue();
            propertiesNames.add(propertyName);
            for (int j = 1; j < colNum; j++) {
                Properties currentP = properties.get(j);
                HSSFCell currentCell = currentRow.getCell(j);
                if (currentCell == null) {
                    currentP.put(propertyName, "");
                } else {
                    currentCell.setCellType(currentCell.CELL_TYPE_STRING);
                    currentP.put(propertyName, currentCell.toString());
                }
            }
        }
        currentRowNum = currentRowNum + rowCount;

        /*
         * Merge default properties with other properties
         */
        for (int j = 2; j < colNum; j++) {
            Properties defaultP = properties.get(1);
            Properties currentP = properties.get(j);
            Set<Object> propertyNames = defaultP.keySet();
            for (Object propertyKey : propertyNames) {
                String key = (String) propertyKey;
                if (currentP.getProperty(key).equals(""))
                    currentP.setProperty(key, defaultP.getProperty(key));
            }

        }

        for (int j = 1; j < colNum; j++) {
            File directory = new File(outputDir + "/" + names.get(j));
            directory.mkdirs();
            File f = new File(directory, filename);
            Properties currentP = properties.get(j);

            saveProperties(propertiesNames, currentP, f);
        }
    }
}