首页 > 其他 > 详细

jxl操作Excel

时间:2014-11-06 13:11:45      阅读:227      评论:0      收藏:0      [点我收藏+]
/**
     * 处理excel数据的方法
     */
    public static Hashtable<String, Vector<Vector<String>>> readExcel(
            String filePath) throws Exception {
        Hashtable<String, Vector<Vector<String>>> datas = new Hashtable<String, Vector<Vector<String>>>();
        InputStream is = null;
        try {
            is = new FileInputStream(filePath);
            WorkbookSettings wkbkSet = new WorkbookSettings();
            wkbkSet.setSuppressWarnings(true);
            Workbook rwb = Workbook.getWorkbook(is, wkbkSet);
            Sheet st[] = rwb.getSheets();
            for (int a = 0; a < st.length; a++) {
                String sheetName = st[a].getName().trim();
                Vector<Vector<String>> sheetDatas = new Vector<Vector<String>>();
                for (int i = 0; i < st[a].getRows(); i++) {
                    Vector<String> rowDatas = new Vector<String>();
                    for (int j = 0; j < st[a].getColumns(); j++) {
                        Cell c = st[a].getCell(j, i);
                        String content = c.getContents().trim();
                        rowDatas.add(content);
                    }
                    sheetDatas.add(rowDatas);
                }
                datas.put(sheetName, sheetDatas);
            }
            rwb.close();
        } catch (Exception e) {
            throw e;
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (Exception e) {
            }
        }
        return datas;
    }
    public static void main(String[] args) throws Exception {
        Hashtable<String, Vector<Vector<String>>> datas = readExcel("E:\\123.xls");
        System.out.println(datas.get("Sheet1"));
    }


jxl操作Excel

原文:http://my.oschina.net/pzxzj/blog/341388

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