Example usage for org.apache.poi.ss.usermodel Cell getStringCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getStringCellValue

Introduction

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

Prototype

String getStringCellValue();

Source Link

Document

Get the value of the cell as a string

For numeric cells we throw an exception.

Usage

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

private String isDvrNumber(Row row, int rowIndex, List<String> dvrNumbers) {
    Cell cell = row.getCell(11);
    Long dvrNumber = null;/*from w  w  w .j  ava 2 s  .c  o  m*/
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 12 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",dvrNumber is not null");
    } else {
        try {
            row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
            String dn = cell.getStringCellValue();
            if (dvrNumbers.size() > 0) {
                if (dvrNumbers.contains(dn)) {
                    throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                            "excel row:" + (rowIndex + 1) + ",cellIndex:" + 12 + ","
                                    + TypeDefinition.DVR_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR
                                    + ",parameter dvrNumber[" + dn + "] invalid !");
                }
                dvrNumber = Long.parseLong(dn);
            }
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 12 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter dvrNumber["
                            + cell.getStringCellValue() + "] invalid !");
        }

    }
    return dvrNumber + "";
}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

public Dvr readDvrCells(Row row, int rowIndex, Organ organ, String standardNumber, List<Manufacturer> manufs,
        List<String> snList) {
    Dvr dvr = new Dvr();
    VideoDeviceProperty property = new VideoDeviceProperty();
    Cell cell = row.getCell(0);
    row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
    dvr.setName(cell.getStringCellValue());

    cell = row.getCell(1);/*from w w  w.j av a 2  s . c o m*/
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex: " + 2 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",subType is not null");
    } else {
        Integer subType = 1;
        try {
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            subType = Integer.parseInt(cell.getStringCellValue());
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 2 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter subType[" + cell.getStringCellValue()
                            + "] invalid !");
        }
        dvr.setSubType("0" + subType);
    }

    cell = row.getCell(2);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 3 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",maxConnect is not null");
    } else {
        Integer maxConnect = 10;
        try {
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            maxConnect = Integer.parseInt(cell.getStringCellValue());
            if (maxConnect < 1 || maxConnect > 32) {
                throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                        "excel row:" + (rowIndex + 1) + ",cellIndex:" + 3 + "," + TypeDefinition.DVR_TEMPLATE
                                + "," + TypeDefinition.PARAMETER_ERROR + ",parameter maxConnect["
                                + cell.getStringCellValue() + "] invalid !");
            }
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 3 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter maxConnect["
                            + cell.getStringCellValue() + "] invalid !");
        }
        dvr.setMaxConnect(maxConnect);
    }

    property.setHeartCycle(120);

    cell = row.getCell(3);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",channelAmount is not null");
    } else {
        Integer channelAmount = 1;
        try {
            row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
            channelAmount = Integer.parseInt(cell.getStringCellValue());
            if (channelAmount < 1 || channelAmount > 1000) {
                throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                        "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.DVR_TEMPLATE
                                + "," + TypeDefinition.PARAMETER_ERROR + ",parameter channelAmount["
                                + cell.getStringCellValue() + "] invalid !");
            }
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter channelAmount["
                            + cell.getStringCellValue() + "] invalid !");
        }
        dvr.setChannelAmount(channelAmount);
    }

    cell = row.getCell(4);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex: " + 5 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",userName is not null");
    } else {
        row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
        String userName = cell.getStringCellValue();
        property.setUserName(userName);
    }

    cell = row.getCell(5);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 6 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",password is not null");
    } else {
        row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
        String password = cell.getStringCellValue();
        property.setPassword(Base64Utils.getBASE64(password.getBytes()));
    }

    cell = row.getCell(6);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 7 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",manufacturer is not null");
    } else {
        String manufacturerId = "1";
        try {
            row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
            manufacturerId = cell.getStringCellValue();
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 7 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter manufacturer["
                            + cell.getStringCellValue() + "] invalid !");
        }
        Manufacturer manuf = findManuf(manufs, manufacturerId, rowIndex, 7, 1);
        dvr.setManufacturer(manuf);
    }

    cell = row.getCell(7);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 8 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",ip is not null");
    } else {
        row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
        if (!isIp(cell.getStringCellValue())) {
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 8 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",ip error");
        } else {
            String lanIp = cell.getStringCellValue();
            dvr.setLanIp(lanIp);
        }
    }

    cell = row.getCell(8);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 9 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",port is not null");
    } else {
        Integer port = 8000;
        try {
            row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
            port = Integer.parseInt(cell.getStringCellValue());
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 9 + "," + TypeDefinition.DVR_TEMPLATE + ","
                            + TypeDefinition.PARAMETER_ERROR + ",parameter port[" + cell.getStringCellValue()
                            + "] invalid !");
        }
        dvr.setPort(port + "");
    }

    cell = row.getCell(9);
    if (cell != null) {
        row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
    }
    dvr.setLocation(cell == null ? " " : cell.getStringCellValue());

    cell = row.getCell(10);
    if (cell != null) {
        row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
    }
    dvr.setNote(cell == null ? "" : cell.getStringCellValue());

    cell = row.getCell(11);
    row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
    dvr.setLinkType(cell.getStringCellValue());

    cell = row.getCell(12);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 12 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",ccs is not null");
    }
    row.getCell(12).setCellType(Cell.CELL_TYPE_STRING);
    LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
    params.put("standardNumber", cell.getStringCellValue());
    dvr.setCcs(ccsDAO.findByPropertys(params).get(0));

    cell = row.getCell(13);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 14 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",transport is not null");
    }
    row.getCell(13).setCellType(Cell.CELL_TYPE_STRING);
    dvr.setTransport(cell.getStringCellValue());

    cell = row.getCell(14);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 15 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",mode is not null");
    }
    row.getCell(14).setCellType(Cell.CELL_TYPE_STRING);
    dvr.setMode(cell.getStringCellValue());

    cell = row.getCell(15);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 16 + "," + TypeDefinition.DVR_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",mode is not null");
    }
    row.getCell(15).setCellType(Cell.CELL_TYPE_STRING);
    property.setDecode(cell.getStringCellValue());
    property.setProtocol(cell.getStringCellValue());
    cell = row.getCell(16);
    if (null != cell) {
        row.getCell(16).setCellType(Cell.CELL_TYPE_STRING);
        String cellSn = cell.getStringCellValue();
        if (StringUtils.isNotBlank(cellSn)) {
            for (String sn : snList) {
                if (sn.equals(cell.getStringCellValue())) {
                    throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                            "excel row:" + (rowIndex + 1) + ",cellIndex:" + 17 + ","
                                    + TypeDefinition.DVR_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR
                                    + ",sn error");
                }
            }
            dvr.setStandardNumber(cellSn);
        } else {
            dvr.setStandardNumber(standardNumber);
        }
    } else {
        dvr.setStandardNumber(standardNumber);
    }

    dvr.setOrgan(organ);
    dvr.setProperty(property);
    String id = (String) new UUIDHexGenerator().generate(null, null);
    dvr.setId(id);
    dvr.setType(TypeDefinition.DEVICE_TYPE_DVR);
    return dvr;
}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

private String isCameraNameExist(List<String> cameraNames, int rowIndex, Row row) {
    Cell cell = row.getCell(0);
    String name = "";
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 1 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",cameraName is not null");

    } else {/*from   w  w w  .  j av a 2s .  c  om*/
        row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
        name = cell.getStringCellValue();
        if (cameraNames.contains(name)) {
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 1 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.CAMERA_NAME_EXIST + ",name[" + name
                            + "] is already exist !");
        }
    }
    return name;
}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

/**
 * //  w  ww .  ja  v a  2s.c  o m
 * dvr????????????dvr??
 * 
 * @param row
 *            
 * @param cameraNumber
 *            ??
 * @param dvr
 *            dvr
 * @param rowIndex
 *            ?
 * @param arrayChannelAmount
 *            dvr?
 * @author wangbinyu
 *         <p />
 *         Create at 2013 ?3:39:57
 */
private void isExistChannelNumber(Row row, Dvr dvr, int rowIndex, List<TemplateDvrIsChannelNumberVO> tdcs) {
    int arrayChannelAmount[] = null;
    for (int i = 0; i < tdcs.size(); i++) {
        if (row.getCell(7).getStringCellValue().equals(tdcs.get(i).getDvrNumber())) {
            arrayChannelAmount = tdcs.get(i).getArrayChannelAmount();
            break;
        }
    }
    int channelAmount = dvr.getChannelAmount();
    Cell cell = row.getCell(3);
    int channelNumber = 0;
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",channelNumber is not null");
    } else {
        try {
            row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
            channelNumber = Integer.parseInt(cell.getStringCellValue());
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_ERROR + ",parameter channelNumber["
                            + cell.getStringCellValue() + "] invalid !");
        }
    }
    if (channelNumber > channelAmount) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.CAMERA_OVER_LIMIT + ",Channel amount[" + channelAmount
                        + "] over limit !");
    }

    if (channelNumber == arrayChannelAmount[channelNumber - 1]) {
        arrayChannelAmount[channelNumber - 1] = -1;
    } else {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 4 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.CAMERA_CHANNEL_NUMBER_EXIST + ",channelId[" + channelNumber
                        + "] is already exist !");
    }
}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

/**
 * // www.j a  va2 s  .c o m
 * ??dvr sn
 * 
 * @param row
 *            
 * @param rowIndex
 *            
 * @return standardNumber
 * @author wangbinyu
 *         <p />
 *         Create at 2013 ?10:52:45
 */
private String findDvrNumber(Row row, int rowIndex) {
    Cell cell = row.getCell(7);
    row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
    String dvrNumberString = cell.getStringCellValue();
    Long dvrNumber = null;
    if (StringUtils.isBlank(dvrNumberString)) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 8 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",dvrNumber is not null");
    } else {
        try {
            dvrNumber = Long.parseLong(dvrNumberString);
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 8 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_ERROR + ",parameter dvrNumber[" + dvrNumberString
                            + "] invalid !");
        }
    }
    return dvrNumber + "";
}

From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java

public Camera readCameraCells(Row row, int rowIndex, Organ organ, Dvr dvr, String standardNumber,
        List<Manufacturer> manufs, List<String> snList) {
    Camera camera = new Camera();
    VideoDeviceProperty property = new VideoDeviceProperty();
    Cell cell = null;
    cell = row.getCell(0);/*  w  w w. j  a  v  a  2s . co m*/
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex:" + 1 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",name is not null");
    } else {
        row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
        camera.setName(cell.getStringCellValue());
    }

    cell = row.getCell(1);
    if (cell == null) {
        throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                "excel row:" + (rowIndex + 1) + ",cellIndex: " + 2 + "," + TypeDefinition.CAMERA_TEMPLATE + ","
                        + TypeDefinition.PARAMETER_NULL + ",subType is not null");
    } else {
        Integer subType = null;
        try {
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            subType = Integer.parseInt(cell.getStringCellValue());
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 2 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_ERROR + ",parameter subType["
                            + cell.getStringCellValue() + "] invalid !");
        }
        if (subType == 1) {
            camera.setSubType(TypeDefinition.SUBTYPE_CAMERA_DEFAULT);
        } else if (subType == 2) {
            camera.setSubType(TypeDefinition.SUBTYPE_CAMERA_BALL);
        }
    }

    cell = row.getCell(2);
    Short storeType = 0;
    if (cell != null) {
        try {
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            storeType = Short.parseShort(cell.getStringCellValue());
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 3 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_ERROR + ",parameter storeType["
                            + cell.getStringCellValue() + "] invalid !");
        }
        property.setStoreType(storeType);
    } else {
        property.setStoreType(storeType);
    }

    cell = row.getCell(3);

    Short channelNumber = null;
    row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
    channelNumber = Short.parseShort(cell.getStringCellValue());
    camera.setChannelNumber(channelNumber);

    cell = row.getCell(4);
    Manufacturer manuf = null;
    if (cell != null) {
        String manufacturerId = "";
        try {
            row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
            manufacturerId = cell.getStringCellValue();
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex:" + 5 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_ERROR + ",parameter channelNumber["
                            + cell.getStringCellValue() + "] invalid !");
        }
        if (StringUtils.isNotBlank(manufacturerId)) {
            manuf = findManuf(manufs, manufacturerId, rowIndex, 5, 2);
        }
    }
    camera.setManufacturer(manuf);

    cell = row.getCell(5);
    if (cell != null) {
        row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
    }
    camera.setLocation(cell == null ? " " : cell.getStringCellValue());

    cell = row.getCell(6);
    if (cell != null) {
        row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
    }
    camera.setNote(cell == null ? " " : cell.getStringCellValue());

    cell = row.getCell(8);
    LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
    if (property.getStoreType() == 1 || property.getStoreType() == 2) {
        if (cell == null) {
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex: " + 9 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_NULL + ",crs is not null");
        }
        row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
        if (StringUtils.isNotBlank(cell.getStringCellValue())) {
            params.put("standardNumber", cell.getStringCellValue());
            camera.setCrs(crsDAO.findByPropertys(params).get(0));
            params.clear();
            property.setCenterStorePlan(TypeDefinition.STORE_PLAN_DEFAULT);
        } else {
            throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                    "excel row:" + (rowIndex + 1) + ",cellIndex: " + 9 + "," + TypeDefinition.CAMERA_TEMPLATE
                            + "," + TypeDefinition.PARAMETER_NULL + ",crs is not null");
        }
    }

    cell = row.getCell(9);
    if (cell != null) {
        row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
        if (StringUtils.isNotBlank(cell.getStringCellValue())) {
            params.put("standardNumber", cell.getStringCellValue());
            camera.setMss(mssDAO.findByPropertys(params).get(0));
            params.clear();
        } else {
            camera.setMss(null);
        }
    }

    cell = row.getCell(10);
    if (cell != null) {
        row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
        camera.setNavigation(cell.getStringCellValue());
    }

    cell = row.getCell(11);
    if (cell != null) {
        row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
        camera.setStakeNumber(cell.getStringCellValue());
    }

    cell = row.getCell(12);
    if (cell != null) {
        row.getCell(12).setCellType(Cell.CELL_TYPE_STRING);
        String cellSn = cell.getStringCellValue();
        if (StringUtils.isNotBlank(cellSn)) {
            for (String sn : snList) {
                if (sn.equals(cell.getStringCellValue())) {
                    throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR,
                            "excel row:" + (rowIndex + 1) + ",cellIndex:" + 13 + ","
                                    + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR
                                    + ",sn error");
                }
            }
            camera.setStandardNumber(cellSn);
        } else {
            camera.setStandardNumber(standardNumber);
        }
    } else {
        camera.setStandardNumber(standardNumber);
    }

    camera.setCreateTime(System.currentTimeMillis());
    camera.setParent(dvr);
    camera.setOrgan(organ);
    camera.setProperty(property);
    camera.setType(TypeDefinition.DEVICE_TYPE_CAMERA);
    return camera;
}

From source file:common.ReadExcelData.java

License:Apache License

public ArrayList<String> getColumnValue(String sheetName, String header) {
    HSSFSheet sheet = workbook.getSheet(sheetName);
    ArrayList<String> list = new ArrayList<String>();
    int index = 0;
    for (Row r : sheet) {
        for (Cell c : r) {
            if (c.getCellType() != Cell.CELL_TYPE_NUMERIC)
                if (c.getStringCellValue().equals(header))
                    index = c.getColumnIndex();
        }// w w w  .  j a v a  2s.  c  o  m
        list.add(r.getCell(index).getStringCellValue());
    }
    return list;
}

From source file:common.ReadExcelData.java

License:Apache License

public ArrayList<String> getRowValue(String sheetName, int row) {
    HSSFSheet sheet = workbook.getSheet(sheetName);
    ArrayList<String> list = new ArrayList<String>();
    Row r = sheet.getRow(row);/*from  w  ww. j  a va2s  .  c o  m*/
    for (Cell c : r) {
        if (c.getCellType() == Cell.CELL_TYPE_STRING)
            list.add(c.getStringCellValue());
        else if (c.getCellType() == Cell.CELL_TYPE_NUMERIC)
            list.add(String.valueOf(c.getNumericCellValue()));
    }
    return list;
}

From source file:common.ReadExcelData.java

License:Apache License

public String getCellValue(int index, String heading) {
    String cellValue = "";
    try {/*from   w w  w.j  a  v a  2  s  .  co m*/
        sheet = workbook.getSheet(sheetName);
        row = sheet.getRow(0);
        int cellNumber = 0;
        for (Cell cell : row) {
            if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                if (cell.getRichStringCellValue().getString().trim().equals(heading)) {
                    cellNumber = cell.getColumnIndex();
                }
            }
        }
        row = sheet.getRow(findRow(sheet, index));
        cell = row.getCell(cellNumber);
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
            cellValue = String.valueOf(((long) cell.getNumericCellValue()));
            break;
        case Cell.CELL_TYPE_STRING:
            cellValue = cell.getStringCellValue();
            break;
        case Cell.CELL_TYPE_BOOLEAN:
            cellValue = String.valueOf(cell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_BLANK:
            cellValue = null;
        }
    } catch (NullPointerException e) {
        cellValue = null;
    }
    return cellValue;
}

From source file:comparararchivos.CompararArchivos.java

/**
 * @param args the command line arguments
 *///from   w  ww  .  j  a va2 s.c  o  m
public static void main(String[] args) {
    // TODO code application logic here
    File excel1 = null;
    FileInputStream fl1 = null;
    XSSFWorkbook book1 = null;

    File excel2 = null;
    FileInputStream fl2 = null;
    XSSFWorkbook book2 = null;

    try {
        excel1 = new File("D:\\Users\\jose.gil\\Documents\\Anotaciones\\ProfesorB.xlsx");
        excel2 = new File("D:\\Users\\jose.gil\\Documents\\Anotaciones\\ProfesorD.xlsx");

        PrintWriter file = new PrintWriter("diferencias.txt", "UTF-8");

        fl1 = new FileInputStream(excel1);
        fl2 = new FileInputStream(excel2);

        book1 = new XSSFWorkbook(fl1);
        book2 = new XSSFWorkbook(fl2);

        XSSFSheet sheet_A = book1.getSheetAt(0);
        XSSFSheet sheet_B = book2.getSheetAt(0);

        Iterator<Row> itrA = sheet_A.iterator();
        Iterator<Row> itrB = sheet_B.iterator();

        int totalDiferencias = 0;
        int numFila = 2;
        while (itrA.hasNext() && itrB.hasNext()) {
            Row rowA = itrA.next();
            Row rowB = itrB.next();
            if (rowA.getRowNum() == 0)
                continue;

            Iterator<Cell> cellitA = rowA.cellIterator();
            Iterator<Cell> cellitB = rowB.cellIterator();

            Cell celA = cellitA.next();
            Cell celB = cellitB.next();

            //Se esta en las celdas del numero de Aviso
            celA = cellitA.next();
            celB = cellitB.next();

            int numAvisoA = (int) celA.getNumericCellValue();
            int numAvisoB = (int) celB.getNumericCellValue();

            if (numAvisoA != numAvisoB) {
                System.out.println("Numero de Aviso: " + numAvisoA);
                continue;
            }

            //Se esta en las celdas de la categoria
            celA = cellitA.next();
            celB = cellitB.next();

            String textA = celA.getStringCellValue();
            //System.out.println("Categoria A: "+textA);
            String textB = celB.getStringCellValue();
            //System.out.println("Categoria B: "+textB);

            if (!textA.equals(textB)) {
                System.out.println("Fila: " + numFila + " Numero de Aviso: " + numAvisoA + " Texto B: " + textA
                        + " - Texto D: " + textB);
                file.println("Fila: " + numFila + " Numero de Aviso: " + numAvisoA + " Texto B: " + textA
                        + " - Texto D: " + textB);
                totalDiferencias++;
            }

            numFila++;
        }

        System.out.println("\nTotal diferencias: " + totalDiferencias);
        file.println("\nTotal diferencias: " + totalDiferencias);

        file.close();

    } catch (FileNotFoundException fe) {
        fe.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }

}