Skip to content

Configuration

Mats Alm edited this page Aug 24, 2022 · 28 revisions

Some properties that controls how EPPlus behaves can be configured via different ways of configuration. This can be done via configuration files, environment variables or via code.

Configurable properties

Name Default value Description Via config file Via environment variable Via code
LicenseContext No default value, must be set. Indicates if EPPlus runs in a commercial or noncommercial context. Value must either be Commercial or NonCommercial x x x
JsonConfigBasePath Current directory of the hosting app Path to the folder where the json config file is. x
JsonConfigFileName appsettings.json File name of the json config file. x
SuppressInitializationExceptions false The default behaviour of EPPlus is that Exceptions occurring during intialization (in the ExcelPackage constructor) are not caught by EPPlus. If this variable is set to true, these Exceptions will be caught and logged. x

The ExcelPackage.Configure method

A static method that should be called before the ExcelPackage constructor is called for the first time. With this method you can specify the location and name of the json configuration file. You can also configure EPPlus to catch Exceptions that are thrown if this file cannot be found or if your process doesn't have previlegies to access the filesystem or environment variables.

These configuration values can only be set via code.

Example:

// set epplus to catch and log Exceptions when the constructor of ExcelPackage executes. Read config values from c:\config\myappsettings.json
ExcelPackage.Configure(x => { 
    x.SuppressInitializationExceptions = true;
    x.JsonConfigFileName = "myappsettings.json";
    x.JsonConfigBasePath = "c:\\config";
});

LicenseContext

This property must be set before the ExcelPackage class is instansiated, if not a LicenseException will be thrown when a debugger is attached.

1. Via code

using OfficeOpenXml;
// if you have a commercial license
ExcelPackage.LicenseContext = LicenseContext.Commercial;
// if you are using epplus for noncommercial purposes, see https://polyformproject.org/licenses/noncommercial/1.0.0/
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

2. Via appSettings.json

{
    {
    "EPPlus": {
        "ExcelPackage": {
            "LicenseContext": "Commercial"
            }
        }
    }
}

3. Via app/web.config

For environments where System.Configuration.ConfigurationManager.Appsettings is supported.

<appSettings>
    <add key="EPPlus:ExcelPackage.LicenseContext" value="NonCommercial" />
</appSettings>

4. Via environment variable EPPlusLicenseContext

Set this variable to either NonCommercial or Commercial. The variable should be set on user- or process-level.

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally