Apache POI是的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能
1.下载开发包解压:
2.引入POI的依赖:
org.apache.poi poi 3.11
3.POI使用:
@Test public void test1() throws FileNotFoundException, IOException{ String filePath = "C:\\Users\\zhaoqx\\Desktop\\资料\\区域导入测试数据.xls"; //包装一个Excel文件对象 HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(filePath))); //读取文件中第一个Sheet标签页 HSSFSheet hssfSheet = workbook.getSheetAt(0); //遍历标签页中所有的行 for (Row row : hssfSheet) { System.out.println(); for (Cell cell : row) { String value = cell.getStringCellValue(); System.out.print(value + " "); } } }