Example usage for org.apache.poi.xssf.usermodel XSSFCell getColumnIndex

List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getColumnIndex

Introduction

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

Prototype

@Override
public int getColumnIndex() 

Source Link

Document

Returns column index of this cell

Usage

From source file:parser.CloudDSFParser.java

License:Apache License

/**
 * Retrieves influencing relations between decisions. All decisions (influencing, affecting,
 * binding) are parsed and stored as basic influencing ones for the cloudDSF.
 * /*from  www.j  a  v a2  s  .  com*/
 * @return
 */
private void setInfluencingRelations() {
    XSSFSheet sheet = workbook.getSheet("Decision Level");
    // Column B has name of start Decision
    int startDecisionColumn = 1;
    // Row 1 has names of endDecision
    Row endDecisionRow = sheet.getRow(1);
    // Iterate over all rows starting at 3
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        XSSFRow row = (XSSFRow) rows.next();
        // Iterate over cells
        Iterator<Cell> cells = row.cellIterator();
        while (cells.hasNext()) {
            XSSFCell cell = (XSSFCell) cells.next();
            String relationName = cell.getStringCellValue();
            if (relationName.equals("Influencing") || relationName.equals("Affecting")
                    || relationName.equals("Binding")) {
                // if type of relationship matches predefined values get names of the two participating
                // decisions
                String startDecision = row.getCell(startDecisionColumn).getStringCellValue();
                String endDecision = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue();
                // add new decision relation
                cdsf.setLegacyDecisionRelation(startDecision, endDecision);
            }
        }
    }
}

From source file:parser.CloudDSFParser.java

License:Apache License

/**
 * Retrieves influencing relations between tasks and decisions.
 *///from  w w  w. ja  v a 2s .co m
private void setInfluencingTasks() {
    XSSFSheet sheet = workbook.getSheet("Task Level");
    // Column A has name of start Task
    int startTaskColumn = 0;
    // Row 1 has names of endDecision
    Row endDecisionRow = sheet.getRow(1);
    // Iterate over all rows
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        XSSFRow row = (XSSFRow) rows.next();
        Iterator<Cell> cells = row.cellIterator();
        while (cells.hasNext()) {
            XSSFCell cell = (XSSFCell) cells.next();
            if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
                // Depending on the relation type source and target are set
                // accordingly
                String relationName = cell.getStringCellValue();
                String sourceDesc = row.getCell(startTaskColumn).getStringCellValue();
                String targetDesc = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue();
                switch (relationName) {
                case "Affecting":
                    cdsf.setTaskRelation(sourceDesc, targetDesc, "oneWay");
                    break;
                case "Both":
                    cdsf.setTaskRelation(sourceDesc, targetDesc, "twoWay");
                    break;
                case "Affected":
                    cdsf.setTaskRelation(sourceDesc, targetDesc, "backwards");
                    break;
                // no default
                }
            }
        }
    }
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Retrieves influencing relations between decisions.
 * /*  ww w.j  a v  a 2 s.  co m*/
 * @return
 */
private void setInfluencingRelations() {
    XSSFSheet sheet = workbook.getSheet("Decision Level");
    // Column B has name of start Decision
    int startDecisionColumn = 1;
    // Row 1 has names of endDecision
    Row endDecisionRow = sheet.getRow(1);
    // Iterate over all rows starting at 3
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        XSSFRow row = (XSSFRow) rows.next();
        // select cell C
        Iterator<Cell> cells = row.cellIterator();
        // Iterate of all cells in row
        while (cells.hasNext()) {
            XSSFCell cell = (XSSFCell) cells.next();
            String relationType = cell.getStringCellValue();
            if (relationType.equals("Influencing") || relationType.equals("Affecting")
                    || relationType.equals("Binding")) {
                // if type of relationship matches predefined values get names of the two participating
                // decisions
                String startDecision = row.getCell(startDecisionColumn).getStringCellValue();
                String endDecision = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue();
                // add decision relation to cloudDSFPlus
                cdsf.setDecisionRelation(startDecision, endDecision, relationType, null);
            }
        }
    }
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Retrieves requiring relations between decisions.
 * /*from ww  w. ja  va2s . com*/
 * @return
 */
private void setRequiringRelations() {
    XSSFSheet sheet = workbook.getSheet("Required Level");
    // Column B has name of start Decision
    int startDecisionColumn = 1;
    // Row 1 has names of endDecision
    Row endDecisionRow = sheet.getRow(1);
    // Iterate over all rows starting at 3
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        XSSFRow row = (XSSFRow) rows.next();
        Iterator<Cell> cells = row.cellIterator();
        while (cells.hasNext()) {
            XSSFCell cell = (XSSFCell) cells.next();
            String relationType = cell.getStringCellValue();
            if (relationType.equals("Requiring")) {
                // if requiring relationship is denoted get names of both decisions
                String startDecision = row.getCell(startDecisionColumn).getStringCellValue();
                String endDecision = endDecisionRow.getCell(cell.getColumnIndex()).getStringCellValue();
                // add requiring relation to cloudDSFPlus
                cdsf.setDecisionRelation(startDecision, endDecision, relationType, null);
            }
        }
    }
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Retrieves relations between outcomes.
 * /*from   w  w w . ja v  a 2 s. c  o m*/
 * @return
 */
private void setInfluencingOutcomes() {
    XSSFSheet sheet = workbook.getSheet("Outcome Level");
    // Column B has name of start Decision
    int startOutcomeColumn = 1;
    // Row 1 has names of endDecision
    Row endOutcomeRow = sheet.getRow(0);
    // Iterate over all rows
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        XSSFRow row = (XSSFRow) rows.next();
        Iterator<Cell> cells = row.cellIterator();
        // Iterate over all cells
        while (cells.hasNext()) {
            XSSFCell cell = (XSSFCell) cells.next();
            String relationType = cell.getStringCellValue();
            if (relationType.equals("in") || relationType.equals("ex") || relationType.equals("a")
                    || relationType.equals("eb") || relationType.equals("aff")) {
                // if relationship is denoted get names of both outcomes
                String startOutcome = row.getCell(startOutcomeColumn).getStringCellValue();
                String endOutcome = endOutcomeRow.getCell(cell.getColumnIndex()).getStringCellValue();
                // add new outcome relation to cloudDSFPlus
                cdsf.setOutcomeRelation(startOutcome, endOutcome, relationType, null, null);
            }
        }
    }
}

From source file:ReadExcel.HSSFReadWrite.java

License:Apache License

private static void startReadXlsxFile(String fileName) {
    try {//from ww w  .j a  v  a2  s.c o m
        XSSFWorkbook wb = HSSFReadWrite.readxlsxFile(fileName);
        System.out.println("Data dump:\n");
        for (int k = 0; k < wb.getNumberOfSheets(); k++) {
            XSSFSheet sheet = wb.getSheetAt(k);
            int rows = sheet.getPhysicalNumberOfRows();
            System.out.println("Sheet " + k + " \"" + wb.getSheetName(k) + "\" has " + rows + " row(s).");
            for (int r = 0; r < rows; r++) {
                XSSFRow row = sheet.getRow(r);
                if (row == null) {
                    continue;
                }
                int cells = row.getPhysicalNumberOfCells();
                System.out.println("\nROW " + row.getRowNum() + " has " + cells + " cell(s).");
                for (int c = 0; c < cells; c++) {
                    XSSFCell cell = row.getCell(c);
                    String value = null;
                    switch (cell.getCellTypeEnum()) {
                    case FORMULA:
                        value = "FORMULA value=" + cell.getCellFormula();
                        break;
                    case NUMERIC:
                        value = "NUMERIC value=" + cell.getNumericCellValue();
                        break;
                    case STRING:
                        value = "STRING value=" + cell.getStringCellValue();
                        break;
                    default:
                    }
                    System.out.println("CELL col=" + cell.getColumnIndex() + " VALUE=" + value);
                }
            }
        }
        wb.close();

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

From source file:utils.ReadWriteExcelFile.java

public static void readXLSXFile(String aFile, int SheetNo) throws IOException {

    InputStream ExcelFileToRead = new FileInputStream(aFile);
    XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);

    XSSFWorkbook test = new XSSFWorkbook();

    XSSFSheet sheet = wb.getSheetAt(SheetNo);
    XSSFRow row;//from  w  w  w .j a v  a 2  s. c  o m
    XSSFCell cell;
    CTSheetDimension dimension = sheet.getCTWorksheet().getDimension();
    String sheetDimensions = dimension.getRef();
    System.out.println(sheetDimensions);
    List<String> dimensions = StringUtils.split(sheetDimensions, ":", true);
    String[] Dimensions = dimensions.get(1).toString().split("(?<=\\D)(?=\\d)");
    int Colums = CharToInt(Dimensions[0]);
    int Rows = Integer.parseInt(Dimensions[1]);
    System.out.println();
    Iterator rows = sheet.rowIterator();
    ArrayList[][] TableName = new ArrayList[Rows][Colums];
    System.out.println(TableName.length);
    int currentRow = 0;
    while (rows.hasNext()) {

        row = (XSSFRow) rows.next();
        Iterator cells = row.cellIterator();
        int currentCell = 0;
        //         System.out.println("currentRow="+currentRow+" And Current Colum is ="+currentCell);
        while (cells.hasNext()) {
            cell = (XSSFCell) cells.next();

            if (cell.getStringCellValue().isEmpty()) {
                TableName[cell.getRowIndex()][cell.getColumnIndex()].add(" - ");
                //               System.out.print(cell.getStringCellValue()+" ");
                //                                        TableName[currentRow][currentCell].add(" ");
                //            System.out.println("Cell Value is : "+cell.toString());
                //                                System.out.println("Empty cell currentRow="+currentRow+" And Current Colum is ="+currentCell);

            } else if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
                System.out.println("current Row=" + cell.getRowIndex() + " And Current Colum is ="
                        + cell.getColumnIndex());
                System.out.println(cell.getRichStringCellValue());
                TableName[cell.getRowIndex()][cell.getColumnIndex()]
                        .add(cell.getRichStringCellValue().toString());
                //                                    System.out.println("Cell Type is :"+cell.getCellType());
                //                                    System.out.println("Cell Value is : "+cell.getRichStringCellValue());
            } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
                TableName[cell.getRowIndex()][cell.getColumnIndex()].add(cell.getNumericCellValue());
                //                                    System.out.println("Cell Type is :"+cell.getCellType());
                //                                    System.out.println("current Row="+cell.getRowIndex()+" And Current Colum is ="+cell.getColumnIndex());
                //                                    int numericValue = (int) cell.getNumericCellValue();
                //                                    System.out.println("Cell Value is : "+numericValue);

            }
            //            else
            //            {
            //               //U Can Handel Boolean, Formula, Errors
            //            }
            currentCell++;
        }
        System.out.println();
        currentRow++;
    }
    for (int i = 0; TableName.length > i; i++) {
        for (int j = 0; TableName[i].length > j; j++) {
            System.out.println(TableName[i][j].toString());
        }

    }
}

From source file:vn.vnpttech.ssdc.nms.webapp.action.MatAction.java

License:Apache License

private List<Materials> processExcelFile(File file) throws IOException {
    List<Materials> list = new ArrayList<Materials>();

    //try {/*ww  w.  j  a  v  a2  s  . c  o m*/
    // Creating Input Stream
    FileInputStream myInput = new FileInputStream(file);

    // Create a workbook using the File System 
    XSSFWorkbook myWorkBook = new XSSFWorkbook(myInput);

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

    Materials item = new Materials();

    /**
     * We now need something to iterate through the cells.*
     */
    Iterator<Row> rowIter = mySheet.rowIterator();
    while (rowIter.hasNext()) {
        XSSFRow myRow = (XSSFRow) rowIter.next();
        if (myRow.getRowNum() != 0) {// loi b? header

            Iterator<Cell> cellIter = myRow.cellIterator();
            while (cellIter.hasNext()) {
                XSSFCell myCell = (XSSFCell) cellIter.next();

                if (myCell.getCellType() != HSSFCell.CELL_TYPE_STRING) {
                    myCell.setCellType(Cell.CELL_TYPE_STRING);
                }
                String value = myCell.getStringCellValue().trim();

                switch (myCell.getColumnIndex()) {
                case 0: //stt ko lam gi
                    //                        item.setProvince(value);
                    break;

                case 1: //name
                    item.setName(value);
                    break;

                //                        case 2: //unit
                //                            if (StringUtils.isNotBlank(value)) {
                //                                item.setUnit(Double.parseDouble(value));
                //                            } else {
                //                                item.setUnit(0);
                //                            }
                //                            break;
                case 2: //unit price
                    if (StringUtils.isNotBlank(value)) {
                        item.setUnitPrice(Double.parseDouble(value));
                    } else {
                        item.setUnitPrice(0.0);
                    }
                    break;

                case 3: //weight
                    if (StringUtils.isNotBlank(value)) {
                        item.setWeight(Double.parseDouble(value));
                    } else {
                        item.setWeight(0.0);
                    }
                    break;

                default:
                    break;
                }

            }
            list.add(item);

            if (item.getName() != null) {
                item = new Materials(); //for next row
            }

        }
    }
    return list;
}