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

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

Introduction

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

Prototype

short getFirstCellNum();

Source Link

Document

Get the number of the first cell contained in this row.

Usage

From source file:vn.com.mks.ca.Setting.java

License:Apache License

/**
 * [Give the description for method].//ww  w  .j a  va 2  s.c  om
 * @param sheetName
 * @param rowIdx start from 0
 * @return
 */
private String[] getDataRow(String sheetName, int rowIdx) {
    Sheet sheet = workbook.getSheet(sheetName);

    if (sheet == null) {
        return null;
    }

    Row row = sheet.getRow(rowIdx);

    if (row == null) {
        return null;
    }

    short minColIx = row.getFirstCellNum();
    short maxColIx = row.getLastCellNum();
    String[] lstData = new String[maxColIx - minColIx];
    Cell cell;
    Object value;
    int i = 0;
    for (short colIx = minColIx; colIx < maxColIx; colIx++) {
        cell = row.getCell(colIx);
        if (cell == null) {
            continue;
        }

        value = PoiUtil.getValue(cell);

        if (value instanceof Date) {
            lstData[i++] = CommonUtil.formatDate((Date) value, Constant.DEF_DATEFMT);
        } else if (value instanceof Double) {
            Double dblValue = (Double) value;
            lstData[i++] = String.valueOf(dblValue.intValue());

        } else if (value != null) {
            lstData[i++] = value.toString();
        } else {
            lstData[i++] = CHARA.BLANK;
        }

    }

    return lstData;
}