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

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

Introduction

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

Prototype

int getRowNum();

Source Link

Document

Get row number this row represents

Usage

From source file:manager.supplier.service.SupplierFileService.java

private List<Metarial> getMetarialListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<Metarial> items = new ArrayList<Metarial>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;//from w w  w  .j  av  a  2 s.  c  om
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(5); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            Metarial item = new Metarial();
            if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                json.put("success", false);
                json.put("message", "?6" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            item.setMaterial_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setMaterial_brand((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"???".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

private List<Competitor> getCompetitorListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<Competitor> items = new ArrayList<Competitor>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;/*from w  ww  . ja v a2  s.c  o m*/
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(7); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            Competitor item = new Competitor();
            if (row.getCell(0) == null || row.getCell(1) == null) {
                json.put("success", false);
                json.put("message", "?8" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            item.setCompetitor_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setCompany_name((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"?".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

private List<Goods> getGoodsListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<Goods> items = new ArrayList<Goods>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;/* w  ww  .j a v a2 s . co m*/
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(4); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            Goods item = new Goods();
            if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                json.put("success", false);
                json.put("message", "?5" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            item.setGoods_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setGoods_brand((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"??".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

private List<Devicelist> getDeviceListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<Devicelist> items = new ArrayList<Devicelist>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;/*from   w w w .ja v  a2 s . c  o m*/
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(3); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            Devicelist item = new Devicelist();
            if (row.getCell(0) == null || row.getCell(5) == null || row.getCell(7) == null) {
                json.put("success", false);
                json.put("message", "?4" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            if (row.getCell(1) != null) {
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            }
            if (row.getCell(2) != null) {
                row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            }
            if (row.getCell(6) != null) {
                row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
            }
            row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
            item.setDevice_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setSpecifications((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            item.setPlace((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
            item.setPrice((row.getCell(3) == null) ? 0 : row.getCell(3).getNumericCellValue());
            item.setBuy_day((row.getCell(4) == null) ? null : row.getCell(4).getDateCellValue());
            item.setDevice_num((int) ((row.getCell(5) == null) ? 0 : row.getCell(5).getNumericCellValue()));
            item.setAdvanced((row.getCell(6) == null) ? "" : row.getCell(6).getStringCellValue());
            item.setCompany_name((row.getCell(7) == null) ? "" : row.getCell(7).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

private List<InvoiceTitle> getTitleListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<InvoiceTitle> items = new ArrayList<InvoiceTitle>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;/*  w w  w  . j a v  a  2s . c o m*/
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(2); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            InvoiceTitle item = new InvoiceTitle();
            if (row.getCell(0) == null || row.getCell(1) == null) {
                json.put("success", false);
                json.put("message", "?3" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            item.setInvoice_title_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setCompany_name((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"?".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

private List<BankAccount> getAccountListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<BankAccount> items = new ArrayList<BankAccount>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;/*from   w  w  w  . j  a  v a  2s .  c  o  m*/
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(1); //?  
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            BankAccount item = new BankAccount();
            if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                json.put("success", false);
                json.put("message", "?2" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            item.setAccount_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setAccount_code((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"?".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:manager.supplier.service.SupplierFileService.java

/**
 * @Description:?EXCEL/*  ww  w  . ja v a  2  s. c om*/
 * SupplierFileService
 * getListFromExcel
 * @param finalFile
 * @param json
 * @param request
 * @return
 * @throws Exception List<SupplierFile>
 * @author yukai
 * 2016-10-13 ?4:11:14
 */
private List<SupplierFile> getSupplierListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
        throws Exception {
    List<SupplierFile> items = new ArrayList<SupplierFile>();
    String fileName = finalFile.getName();

    boolean isE2007 = false; //?excel2007?  
    if (fileName.endsWith("xlsx")) {
        isE2007 = true;
    }
    InputStream input = new FileInputStream(finalFile);
    Workbook wb = null;
    //??(20032007)??  
    if (isE2007) {
        wb = new XSSFWorkbook(input);
    } else {
        wb = new HSSFWorkbook(input);
    }
    Sheet sheet = wb.getSheetAt(0); //?  
    if (!sheet.iterator().hasNext()) {
        json.put("success", false);
        json.put("message", "excel");
        return items;
    }
    int trLength = sheet.getLastRowNum();
    if (trLength <= 2) {
        json.put("success", false);
        json.put("message", "?");
    }
    for (Row row : sheet) { //?
        //
        if (row.getRowNum() > 2) {
            SupplierFile item = new SupplierFile();
            if ((row.getCell(0) == null || row.getCell(0).toString().equals(""))
                    && (row.getCell(1) == null || row.getCell(1).toString().equals(""))
                    && (row.getCell(2) == null || row.getCell(2).toString().equals(""))
                    && (row.getCell(3) == null || row.getCell(3).toString().equals(""))
                    && (row.getCell(4) == null || row.getCell(4).toString().equals(""))
                    && (row.getCell(5) == null || row.getCell(5).toString().equals(""))
                    && (row.getCell(6) == null || row.getCell(6).toString().equals(""))
                    && (row.getCell(7) == null || row.getCell(7).toString().equals(""))
                    && (row.getCell(8) == null || row.getCell(8).toString().equals(""))
                    && (row.getCell(9) == null || row.getCell(9).toString().equals(""))
                    && (row.getCell(10) == null || row.getCell(10).toString().equals(""))
                    && (row.getCell(11) == null || row.getCell(11).toString().equals(""))) {
                if (row.getRowNum() == 3) {
                    json.put("success", false);
                    json.put("message", "?");
                }
                break;//?
            }
            if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null
                    || row.getCell(3) == null || row.getCell(4) == null || row.getCell(5) == null
                    || row.getCell(6) == null || row.getCell(7) == null || row.getCell(8) == null
                    || row.getCell(9) == null || row.getCell(10) == null) {
                json.put("success", false);
                json.put("message", "" + (row.getRowNum() + 1) + "??");
                break;
            }
            row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
            row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
            //if(row.getCell(9)!=null){
            row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
            //    }
            //if(row.getCell(10)!=null){
            row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
            //   }
            if (row.getCell(11) != null) {
                row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
            }
            item.setCpyname_cn((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
            item.setCorporation((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
            item.setContact_addr((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
            item.setContacts((row.getCell(3) == null) ? "" : row.getCell(3).getStringCellValue());
            item.setM_phone((row.getCell(4) == null) ? "" : row.getCell(4).getStringCellValue());
            item.setClass_name((row.getCell(5) == null) ? "" : row.getCell(5).getStringCellValue());
            item.setNature_name((row.getCell(6) == null) ? "" : row.getCell(6).getStringCellValue());
            item.setReg_fund((row.getCell(7) == null) ? 0 : row.getCell(7).getNumericCellValue());
            item.setCurrency_name((row.getCell(8) == null) ? "" : row.getCell(8).getStringCellValue());
            item.setReg_account((row.getCell(9) == null) ? "" : row.getCell(9).getStringCellValue());
            item.setPassword((row.getCell(10) == null) ? "" : row.getCell(10).getStringCellValue());
            item.setReg_email((row.getCell(11) == null) ? "" : row.getCell(11).getStringCellValue());
            items.add(item);
        } else if (row.getRowNum() == 1) {//
            String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
            if (!"".equals(name)) {
                json.put("success", false);
                json.put("message", "?");
                break;
            }
        }
    }
    input.close();
    return items;
}

From source file:me.utils.excel.ExportExcelme.java

License:Open Source License

/**
 * ?/*  ww w  .  j a  v  a 2 s .co  m*/
 * @param row 
 * @param column ?
 * @param val 
 * @param align ??1?23??
 * @return ?
 */
public Cell addCell(Row row, int column, Object val, int align) {
    Cell cell = row.createCell(column);
    CellStyle style = styles.get("data" + (align >= 1 && align <= 3 ? align : ""));
    try {
        if (val == null) {
            cell.setCellValue("");
        } else if (val instanceof String) {
            cell.setCellValue((String) val);
        } else if (val instanceof Integer) {
            cell.setCellValue((Integer) val);
        } else if (val instanceof Long) {
            cell.setCellValue((Long) val);
        } else if (val instanceof Double) {
            cell.setCellValue((Double) val);
        } else if (val instanceof Float) {
            cell.setCellValue((Float) val);
        } else if (val instanceof Date) {
            DataFormat format = wb.createDataFormat();
            style.setDataFormat(format.getFormat("yyyy-MM-dd"));
            cell.setCellValue((Date) val);
        } else {
        }
    } catch (Exception ex) {
        log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString());
        cell.setCellValue(val.toString());
    }
    cell.setCellStyle(style);
    return cell;
}

From source file:me.utils.excel.ExportExcelme.java

License:Open Source License

/**
 * ?annotation.ExportField?//  w  ww  . j a va2s .co  m
 * @return list ?
 */
public <E> ExportExcelme setDataList(List<E> list, List<String> propertyNames) {
    for (E e : list) {
        int colunm = 0;
        Row row = this.addRow();
        StringBuilder sb = new StringBuilder();
        for (String properyName : properyNames) {
            Object val = null;
            // Get entity value
            try {
                val = Reflections.invokeGetter(e, properyName);
            } catch (Exception ex) {
                // Failure to ignore
                log.info(ex.toString());
                val = "";
            }
            this.addCell(row, colunm++, val, 0);//?
            sb.append(val + ", ");
        }
        log.debug("Write success: [" + row.getRowNum() + "] " + sb.toString());
    }
    return this;
}

From source file:misuExcel.excelAdd.java

License:Open Source License

private void examExcel() {
    Log.info("excamExcel");
    if (excel != null) {
        if (names != null && names.size() > 0) {
            Sheet sheet = excel.getSheetAt(sheetNum);
            initList(names.size());/*  w w  w .  java 2  s. c  o m*/
            nones = new ArrayList<Integer>();
            Boolean isAdd = false;
            for (int j = addJpanel.ignore_Row; j <= sheet.getLastRowNum(); j++) {
                Row row = sheet.getRow(j);
                if (row != null) {
                    Cell cell = row.getCell(cellNum);
                    String str = getCellString(cell);
                    Log.info(" " + str);
                    for (int i = 0; i < names.size(); i++) {
                        if (str != null && str.equals(names.get(i))) {
                            isAdd = true;
                            addList.get(i).add(row.getRowNum());
                            break;
                        }
                    } //end names for   
                    if (!isAdd) {
                        nones.add(row.getRowNum());
                    }
                    isAdd = false;
                }
            } //end for
        } else {
            Log.info("target is none");
        }
    } else {
        Log.info("excel is not exit");
    }
}