码迷,mamicode.com
首页 > 其他好文 > 详细

从excel表中导出数据

时间:2016-04-20 11:19:10      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

File file = new File(excelFileName);// excelFileName:文件地址

       InputStream stream;

       Workbook rwb = null;

       Cell cell = null;

       Sheet sheet = null;

       try {

           stream = FawenPlugin.class.getResourceAsStream("发文表.xls");

           // stream = new FileInputStream(file);

           rwb = Workbook.getWorkbook(stream);

       } catch (FileNotFoundException e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       } catch (BiffException e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       } catch (IOException e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       }

       // 读取主表excel表格的信息存入iolist

       System.out.println("---------------读取主表中的数据---------------");

       List<String[]> iolist = new ArrayList<String[]>();

       sheet = rwb.getSheet(0);

       for (int i = 1; i < sheet.getRows(); i++) {

           String[] str = new String[sheet.getColumns()];

           for (int j = 0; j < sheet.getColumns(); j++) {

              cell = sheet.getCell(j, i);

              str[j] = cell.getContents();

           }

           // 获得文件流里的内容

           iolist.add(str);

       }

从excel表中导出数据

标签:

原文地址:http://www.cnblogs.com/lzw0414/p/5411549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!