zoukankan      html  css  js  c++  java
  • .net NPOI C#处理Excel的类库使用

    ----------------------------------------------------------
    - .net NPOI C#处理Excel的类库使用
    https://www.nuget.org/packages/NPOI/
    VS->工具->程序包管理器控制台 运行 PM> Install-Package NPOI -Version 2.3.0
    相关DLL引用自动添加到项目中,命名空间中添加如下声明:
    using NPOI.XSSF.UserModel;
    using NPOI.SS.UserModel;

    -------------------------------------------------------
    - 用nuget下载旧版本的软件包
    SharpZipLib 必须用0.86版本的,否则NPOI打开EXCEL时会出错。
    如果更新了SharpZipLib到1.0.0版本,必须roll back到0.86.0版,或者卸载重新安装NPOI。

    在Visual Studio中打开包管理器控制台 – 它在工具/ NuGet包管理器/包管理器控制台中。然后运行Install-Package命令:
    Install-Package ICSharpCode.SharpZipLib -Version 0.86.0.518 或者0.86.0

    编辑:
    为了列出包的版本,您可以使用带有远程参数和过滤器的Get-Package命令:

    Get-Package -ListAvailable -Filter Common.Logging -AllVersions
    通过在Install-Package命令中的版本选项后按Tab键,可以获得最新可用版本的列表。

    I also met this problem with VS2017, NPOI 2.3.0 and SharpZipLib 1.0.0.
    I didn't solve the problem changing the verison of the SharpZipLib to 0.86 in NuGet. After test, I found that it should also delete the below content in the App.config if it has that:

    <assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.999" newVersion="1.0.0.999"/>
    So that, not only roll back the verison of the SharpZipLib to 0.86, but also modify the App.config.

    ------------------------------------------------------------
    Excel 用NPOI编辑写入后打不开,尝试以下解决:
    FileMode.Open is working with .xls files but not .xlsx files.
    using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
    {
    workbook.Write(file);
    }

    I think the problem is that you are reading from, and writing to, the same FileStream. You should be doing the read and write using separate streams. Try it like this:

    string newPath = @"C:MyPath est.xlsx";

    // read the workbook
    IWorkbook wb;
    using (FileStream fs = new FileStream(newPath, FileMode.Open, FileAccess.Read))
    {
    wb = new XSSFWorkbook(fs);
    }

    // make changes
    ISheet s = wb.GetSheetAt(0);
    IRow r = s.GetRow(0) ?? s.CreateRow(0);
    ICell c = r.GetCell(1) ?? r.CreateCell(1);
    c.SetCellValue("test2");

    // overwrite the workbook using a new stream
    using (FileStream fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
    {
    wb.Write(fs);
    }

  • 相关阅读:
    Promise 解决回调地狱问题
    同步 异步 API 区别
    静态资源 读取方法
    路由
    HTTP 协议 get post 请求方式
    linux 查看日志
    putty完全使用手册--多窗口---git提交---连接数据库--自动日志显示
    strpos 返回0时 ,比较false 不能加单引号
    禁止使用test类的就是禁止使用本来的$this对象.可以调用父类的对象
    大D实例化model-->调用自定义类方法,大M调用原声model方法
  • 原文地址:https://www.cnblogs.com/CCJVL/p/10913208.html
Copyright © 2011-2022 走看看