标签:
public static List<PlatRule> readExcel(File file) throws Exception{ InputStream inputStream = new FileInputStream(file); String fileName = file.getName(); Workbook wb = null; if(fileName.endsWith("xls")){ wb = new HSSFWorkbook(inputStream);//解析xls格式 }else if(fileName.endsWith("xlsx")){ wb = WorkbookFactory.create(inputStream);//解析xlsx格式 } Sheet sheet = wb.getSheetAt(0);//第一个工作表 int firstRowIndex = sheet.getFirstRowNum()+2; int lastRowIndex = sheet.getLastRowNum(); PlatRule rule; List<PlatRule> ruleList = new ArrayList<PlatRule>(); for(int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex ++){ rule= new PlatRule(); Row row = sheet.getRow(rIndex); if(row != null){ rule.setRuleName(row.getCell(0)==null?"":row.getCell(0).toString()); rule.setRuleType(row.getCell(1)==null?"":row.getCell(1).toString()); rule.setRiskType(row.getCell(3)==null?"":row.getCell(3).toString()); rule.setRuleNo(row.getCell(4)==null?"":row.getCell(4).toString()); rule.setPackages(row.getCell(6)==null?"":row.getCell(6).toString()); rule.setObjects(row.getCell(7)==null?"":row.getCell(7).toString()); rule.setFunctions(row.getCell(8)==null?"":row.getCell(8).toString()); rule.setDescription(row.getCell(9)==null?"":row.getCell(9).toString()); } ruleList.add(rule); rule=null; } return ruleList; }
标签:
原文地址:http://my.oschina.net/u/1246433/blog/416588