java解析excel

来源:互联网 发布:sql 查询多条结果合并 编辑:程序博客网 时间:2024/06/11 13:13

1-----导入包

     commons-collections4-4.1.jar

       poi-3.17-beta1.jar
        poi-examples-3.17-beta1.jar
        poi-excelant-3.17-beta1.jar
        poi-ooxml-3.17-beta1.jar
        poi-ooxml-schemas-3.17-beta1.jar
        poi-scratchpad-3.17-beta1.jar
        xmlbeans-2.6.0.jar

 


2------main方法里面

     //创建工作本
        XSSFWorkbook xw=new XSSFWorkbook("e:\\share.xlsx");
        //得到工作簿
        XSSFSheet sheet=xw.getSheetAt(0);
        //
        String name=null,age=null,id=null;
        for(int i=sheet.getFirstRowNum();i<=sheet.getLastRowNum();i++){
            
            //得到行
            XSSFRow row=sheet.getRow(i);
            for(int j=row.getFirstCellNum();j<row.getLastCellNum();j++){
                //得到列
                XSSFCell cell=row.getCell(j);
                if(cell.getCellType()==0)
                    cell.setCellType(0);
                System.out.print(cell+"\t");
            }
            System.out.println();
        }
       

3-------效果

     学号    姓名    年龄    
      1        aa        11    
      2        bb        22   

   

原创粉丝点击