[Java]通过Poi包读取Excel表格
2017-05-18 14:38
411 查看
public List<EntBusinessCard> readCardExcel() throws IOException { XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream("D:\\buyal\\名片总和.xlsx")); EntBusinessCard card = null; List<EntBusinessCard> list = new ArrayList<EntBusinessCard>(); for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++){ XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet); if(hssfSheet == null){ continue; } for(int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++){ XSSFRow hssfRow = hssfSheet.getRow(rowNum); if(hssfRow != null){ card = new EntBusinessCard(); card.setProperty(hssfRow.getCell(0) == null ?"":getValue(hssfRow.getCell(0))); card.setRole(hssfRow.getCell(1) == null ?"":getValue(hssfRow.getCell(1))); card.setName(hssfRow.getCell(2) == null ?"":getValue(hssfRow.getCell(2))); card.setDirect(hssfRow.getCell(3) == null ?"":getValue(hssfRow.getCell(3))); card.setPostcode(hssfRow.getCell(4) == null ?"":getValue(hssfRow.getCell(4))); card.setRealaddress(hssfRow.getCell(5) == null ?"":getValue(hssfRow.getCell(5))); card.setEnttype(hssfRow.getCell(6) == null ?"":getValue(hssfRow.getCell(6))); card.setLine(hssfRow.getCell(7) == null ?"":getValue(hssfRow.getCell(7))); card.setMainproduct(hssfRow.getCell(8) == null ?"":getValue(hssfRow.getCell(8))); card.setMainproductpic(hssfRow.getCell(9) == null ?"":getValue(hssfRow.getCell(9))); card.setScale(hssfRow.getCell(10) == null ?"":getValue(hssfRow.getCell(10))); card.setUrl(hssfRow.getCell(11) == null ?"":getValue(hssfRow.getCell(11))); card.setFax(hssfRow.getCell(12) == null ?"":getValue(hssfRow.getCell(12))); card.setWorkshopstatus(hssfRow.getCell(13) == null ?"":getValue(hssfRow.getCell(13))); card.setCapacity(hssfRow.getCell(14) == null ?"":getValue(hssfRow.getCell(14))); card.setContract(hssfRow.getCell(15) == null ?"":getValue(hssfRow.getCell(15))); card.setTele(hssfRow.getCell(17) == null ?"":getValue(hssfRow.getCell(17))); card.setEmail(hssfRow.getCell(18) == null ?"":getValue(hssfRow.getCell(18))); card.setIntroduce(hssfRow.getCell(19) == null ?"":getValue(hssfRow.getCell(19))); list.add(card); } } } return list; }
getValue()
public String getValue(XSSFCell hssfCell){ if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) { // 返回布尔类型的值 return String.valueOf(hssfCell.getBooleanCellValue()); } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) { // 返回数值类型的值 return String.valueOf(hssfCell.getNumericCellValue()); } else { // 返回字符串类型的值 return String.valueOf(hssfCell.getStringCellValue()); } }
EntBusinessCard 类
public class EntBusinessCard { private String property; private String role; private String name; private String direct; private String postcode; private String realaddress; private String enttype; private String line; private String mainproduct; private String mainproductpic; private String scale; private String url; private String fax; private String workshopstatus; private String capacity; private String contract; private String tele; private String email; private String introduce; getter()。。。 setter()。。。 }
相关文章推荐
- java通过POI解析Excel表格内容
- Java通过poi组件usermodel读取Excel
- JAVA 通过poi 读取 本地excel(.xls,.xlsx)文件,文件中 包含图片
- java SpringMVC中 POI读取数据库数据并写入Excel表格中,并实现下载功能
- Java中通过POI读取Excel 2003 - 2007的xls,xlsx格式
- java中用poi处理Excel表格之读取(2003和2007通用方法)
- poi读取Excel时日期为数字 的解决方法 转载 2017年12月14日 10:31:14 标签:poi /excel /java 19 在使用poi解析Excel文件时,会发现,表格中的日期解析出
- JAVA:通过poi读取excel
- java通过poi读取excel中的日期类型数据或自定义类型日期
- JAVA入门之如何通过 POI 读取并修改 Excel(转载)
- java通过poi解析Excel文件,直接读取客户端文件
- java 通过poi 读取Excel 写入sqlser mysql
- Java 操作 Excel (读取Excel2003 2007,Poi实现)
- java的poi技术读取和导入Excel
- Java POI 读取Excel-从开始到实例
- 使用java读取Excel——poi
- java利用poi读取excel
- 转:通过 POI 获取图片在 Excel 表格中的位置
- 【JAVA】poi操作,excel读取数据。