首页 > 其他 > 详细

用jxl来读取excel单元格中的数据

时间:2014-03-14 17:07:33      阅读:517      评论:0      收藏:0      [点我收藏+]

 //读取excel文件拼接sql语句插入数据库
    public  void insertdata(String filepath,String tableName)
    {
        //引用jxl包中的wookbook 类来操作excel
        jxl.Workbook jwb=null;
        InputStream in=null;

        //读取excel文件
        try {
            in=new FileInputStream(filepath);
            jwb= Workbook.getWorkbook(in);     //从输入流中创建workbook对象
            Sheet rs=jwb.getSheet(0);              //读取第一个sheet表
            int rscolums=rs.getColumns();      //获取sheet表中的列数,下同
            int rsrows=rs.getRows();

            ……

                  Cell cell=rs.getCell(i,0);          //用于获取第一张sheet表中第1行的内容
               ……
                    Cell cell=rs.getCell(j,i);        //读取sheet表中第i行j列的单元格
                    String content=cell.getContents();       //存放取出来的单个单元格
                     System.out.println(content);
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (BiffException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }finally {
            if(jwb!=null)
                jwb.close();
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }

    }

}

用jxl来读取excel单元格中的数据,布布扣,bubuko.com

用jxl来读取excel单元格中的数据

原文:http://www.cnblogs.com/Likyn/p/3600217.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!