downloadExcel public void doImport(InputStream is) throws Exception{//读取工作簿Workbook wb = null;try {wb = new HSSFWorkbook(is);//得到第一个工作表Sheet sheet = wb.getSheetAt(0);//得到 工作表名称String sheetName = sheet
public void doImport(InputStream is) throws Exception{ //读取工作簿 Workbook wb = null; try { wb = new HSSFWorkbook(is); //得到第一个工作表 Sheet sheet = wb.getSheetAt(0); //得到 工作表名称 String sheetName = sheet.getSheetName(); String type = ""; if("供应商".equals(sheetName)){ type = Supplier.TYPE_PURCHASE; } if("客户".equals(sheetName)){ type = Supplier.TYPE_CUSTOMER; } int rowCnt = sheet.getLastRowNum();//最后一行的索引 Row row = null; for(int i = 1; i <= rowCnt; i++){ row = sheet.getRow(i); //供应商名称 String name = row.getCell(0).getStringCellValue(); //构建查询条件 Supplier supplier = new Supplier(); //设置查询条件 supplier.setName(name); Listlist = supplierDao.getList(null, supplier, null); if(list.size() > 0){ //存在, 进入持久化 supplier = list.get(0); } supplier.setAddress(row.getCell(1).getStringCellValue()); supplier.setContact(row.getCell(2).getStringCellValue()); supplier.setTele(row.getCell(3).getStringCellValue()); supplier.setEmail(row.getCell(4).getStringCellValue()); //不存在,就新增 if(list.size() == 0){ //设置类型 supplier.setType(type); supplierDao.add(supplier); } } } finally { if(null != wb){ wb.close(); } } }