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

 //读取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.
            }
        }

    }

}

转载于:https://www.cnblogs.com/Likyn/p/3600217.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值