zoukankan      html  css  js  c++  java
  • JAVA:通过poi读取excel

    POI是一个apache开源的jar包,可以通过搜索 java POI找到官网,并下载开发包.

    包含的功能:

    可以读取excel2003,2007,2010等。

    读取excel2007/2010的代码:

    public static boolean isNumeric(String str) {
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
    
    public static List<List<String>> readXlsx(String path) throws Exception {
        InputStream is = new FileInputStream(path);
        @SuppressWarnings("resource")
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
        List<List<String>> result = new ArrayList<>();
    
        for (int sheetIx = 0; sheetIx < xssfWorkbook.getNumberOfSheets(); sheetIx++) {
            XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(sheetIx);
            if (xssfSheet == null)
                continue;
    
            for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
                XSSFRow xssfRow = xssfSheet.getRow(rowNum);
    
                int minColIx = xssfRow.getFirstCellNum();
                int maxColIx = xssfRow.getLastCellNum();
                List<String> rowList = new ArrayList<>();
                for (int colIx = minColIx; colIx < maxColIx; colIx++) {
                    XSSFCell cell = xssfRow.getCell(colIx);
                    if (cell == null)
                        continue;
                    rowList.add(cell.toString());
                }
                result.add(rowList);
            }
        }
        return result;
    }
  • 相关阅读:
    metasploit--multi/samba/usermap_script
    msfcli 不能使用,在新版metasploit不再有效,推荐使用msfconsole
    test.fire渗透测试
    metasploit服务扫描与查点
    Synchronized底层实现
    正在使用的IDEA插件
    JavaWeb
    设计模式
    MySQL
    计算机网络
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/6168365.html
Copyright © 2011-2022 走看看