zoukankan      html  css  js  c++  java
  • NPO兼容xlsx 和xls 微软和金山都可用

     在导入Excel的时候,尽量能判断导入Excel的版本,调用不同的方法。

       HSSFWorkbook  对应xls 版本

       XSSFWorkbook  对应xlsx 版本

       Workbook wb = WorkbookFactory.create(is);//自动兼容版本

    /**
         * Creates the appropriate HSSFWorkbook / XSSFWorkbook from
         *  the given InputStream.
         * Your input stream MUST either support mark/reset, or
         *  be wrapped as a {@link PushbackInputStream}!
         */
        public static Workbook create(InputStream inp) throws IOException, InvalidFormatException {
            // If clearly doesn't do mark/reset, wrap up
            if(! inp.markSupported()) {
                inp = new PushbackInputStream(inp, 8);
            }
            
            if(POIFSFileSystem.hasPOIFSHeader(inp)) {
                return new HSSFWorkbook(inp);
            }
            if(POIXMLDocument.hasOOXMLHeader(inp)) {
                return new XSSFWorkbook(OPCPackage.open(inp));
            }
            throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
        }

     其他操作一致  自行百度

  • 相关阅读:
    CSS+JS实现兼容性很好的无限级下拉菜单
    自动切换的JS菜单
    (2)C#连sqlite
    protobuf编译器
    (67) c# 序列化
    (66) c# async await
    (65)C# 任务
    mbatis 入门
    (64)C# 预处理器指令
    (63)C# 不安全代码unsafe
  • 原文地址:https://www.cnblogs.com/manwwx129/p/14387682.html
Copyright © 2011-2022 走看看