Epplus 8+ 之后非商业许可证的设置方法
Epplus 8+ 之后非商业许可证的设置变了如果还用普通的方法会报错
Unhandled exception. OfficeOpenXml.LicenseContextPropertyObsoleteException: Please use the static ‘ExcelPackage.License’ property to set the required license information from EPPlus 8 and later versions. For more info see http://epplussoftware.com/developers/licensenotsetexception.
at OfficeOpenXml.ExcelPackage.set_LicenseContext(Nullable`1 value)
at Program.$(String[] args) in D:\Study\Rider\WorkSpace\Test\GetFieldNoSame\Program.cs:line 52
这个时候需要使用
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization");//组织
//或者
ExcelPackage.License.SetNonCommercialPersonal("My Name");//个人
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_46319477/article/details/147235455
以下是官方文档介绍
The license can be set in three different ways:
1. Use the License property on the ExcelPackage class
// If you are a Noncommercial organization.
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization"); //This will also set the Company property to the organization name provided in the argument.
using(var package = new ExcelPackage(new FileInfo("MyWorkbook.xlsx")))
{
}
// If you use EPPlus for Noncommercial personal use.
ExcelPackage.License.SetNonCommercialPersonal("My Name"); //This will also set the Author property to the name provided in the argument.
using(var package = new ExcelPackage(new FileInfo("MyWorkbook.xlsx")))
{
}
2. appSettings.json
{
{
"EPPlus": {
"ExcelPackage": {
"License": "NonCommercialOrganization:The noncommercial organization" //Please provide the name of the noncommercial organization you represent.
}
}
}
}
{
{
"EPPlus": {
"ExcelPackage": {
"License": "NonCommercialPersonal:Your Name" //Please provide your name
}
}
}
}
...or in the app.config...
<appSettings>
<add key="EPPlus:ExcelPackage:License" value="NonCommercialPersonal:Your name" />
</appSettings>
<appSettings>
<add key="EPPlus:ExcelPackage:License" value="NonCommercialOrganization:Your organization" />
</appSettings>
3. Set the environment variable 'EPPlusLicense'
This might be the easiest way of configuring this. The example below is using the SETX command in the Windows console.
Noncommercial organization...
> SETX EPPlusLicense "NonCommercialOrganization:The Noncommercial organization"
Personal use...
> SETX EPPlusLicense "NonCommercialPersonal:Your Name"
The variable can be set on the process, user or machine level.
Developer resources
A more detailed getting started information is available in our developer wiki.
Our sample projects on github is a good starting point. Here you will also find the source code for EPPlus, our issue tracker and branches for our ongoing new development.
More developer information can be found here.
来源地址:https://epplussoftware.com/en/Home/GettingStartedCommunityLicense