如何高效使用Spring POI进行数据处理?

更新于
2026-10-12 10:50:49
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计229个文字,预计阅读时间需要1分钟。

如何高效使用Spring POI进行数据处理?

javapublic void downloadExcel(InputStream is) throws Exception { Workbook wb=null; try { wb=new HSSFWorkbook(is); Sheet sheet=wb.getSheetAt(0); String sheetName=sheet.getName(); } catch (Exception e) { throw e; }}

如何高效使用Spring POI进行数据处理?

downloadExcel

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); List list = 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(); } } }

本文共计229个文字,预计阅读时间需要1分钟。

如何高效使用Spring POI进行数据处理?

javapublic void downloadExcel(InputStream is) throws Exception { Workbook wb=null; try { wb=new HSSFWorkbook(is); Sheet sheet=wb.getSheetAt(0); String sheetName=sheet.getName(); } catch (Exception e) { throw e; }}

如何高效使用Spring POI进行数据处理?

downloadExcel

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); List list = 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(); } } }