使用POI解析Excel文件

Apache POIApache软件基金会的开放源码函式库,POI提供APIJava程序对Microsoft Office格式档案读和写的功能。

下载开发包:

解压上面的zip文件:

在项目中引入POI的依赖:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.11</version>
</dependency>

poi测试使用

@Test
    public void test1() throws Exception {
        String filePath = "D:\workspaceEclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\bos-web\upload_08521568_73df_4dc5_b771_538c06aa7ab2_00000002.tmp";
        //包装exl文件对象
        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(filePath)));
        //读取exl中的sheet标签页
        HSSFSheet sheetAt = workbook.getSheetAt(0);
        //遍历标签页中所有的行
        for (Row row : sheetAt) {
            //遍历单元格
            for (Cell cell : row) {
                //读取单元格中的值
                String cellValue = cell.getStringCellValue();
                System.out.println(cellValue);
            }
        }
    }
原文地址:https://www.cnblogs.com/FanJava/p/9260159.html