How do I add the NPOI library to a .NET Core 1.0 project?

為{幸葍}努か 提交于 2019-12-13 17:22:37

问题


I would like to add the NPOI library to my .NET Core project. I want to work with xls and xlsx files.


回答1:


There are 4 steps to add the NPOI library to a .NET Core project.

  1. Add net451 as a dependency under the frameworks property in the project.json file and include a reference to the NPOI library:

    "frameworks": {
     "netcoreapp1.0": {
       "imports": [
         "dotnet5.6",
         "portable-net45+win8"
       ]
     },
     "net451": {
       "dependencies": {
          "NPOI": "2.2.1"
       }
      }
    },
    
  2. In the project.json file, add runtimes as a top-level property:

     "runtimes": {
     "win7-x64": {},
     "win7-x86": {},
     "osx.10.11-x64": {},
     "ubuntu.14.04-x64": {},
     "centos.7-x64": {},
     "rhel.7.2-x64": {},
     "debian.8-x64": {}
    }
    
  3. In the project.json file, remove the Microsoft.NETCore.App property from the top-level property dependencies

    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    
  4. In the project.json file, remove the netcoreapp1.0 property under the top-level frameworks property:

     "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    },
    

Example of complete project.json file:

 {
  "userSecretsId": "aspnet-MyProjectName-xxxxxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxxxx",

  "dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": {
      "version": "1.0.0",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "MailKit": "1.4.1"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "net451": {
      "dependencies": {
        "NPOI": "2.2.1"
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "runtimes": {
    "win7-x64": {},
    "win7-x86": {},
    "osx.10.11-x64": {},
    "ubuntu.14.04-x64": {},
    "centos.7-x64": {},
    "rhel.7.2-x64": {},
    "debian.8-x64": {}      
  }
}


来源:https://stackoverflow.com/questions/39041097/how-do-i-add-the-npoi-library-to-a-net-core-1-0-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!