ExcelEi 1.0.7

dotnet add package ExcelEi --version 1.0.7
                    
NuGet\Install-Package ExcelEi -Version 1.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExcelEi" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ExcelEi" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="ExcelEi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ExcelEi --version 1.0.7
                    
#r "nuget: ExcelEi, 1.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ExcelEi@1.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ExcelEi&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=ExcelEi&version=1.0.7
                    
Install as a Cake Tool

ExcelEi

Library for excel export-import

It builds on top of EPPlus, ExcelDataReader and AutoMapper. Supported frameworks: .NET Framework 4.6.1; .NET Standard 2.0.

Import example:

    public class NameValue
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }

    public void Foo()
    {
        var excelFilePath = "c:\\file.xlsx";
        var package = new ExcelPackage(new FileInfo(excelFilePath));

        var tableReader = ExcelTableReader.ReadContiguousTableWithHeader(package.Workbook.Worksheets[1], 1);

        var pocoReader = new TableMappingReader<NameValue>()
            .Map(o => o.Name)
            .Map(o => o.Value);

        IList<NameValue> pocoList = pocoReader.Read(tableReader);
    }

Export example:


        var outPath = "c:\\out.xlsx";
        var package = new ExcelPackage(new FileInfo(outPath));

        var dataSetExportConfig = new DataSetExportAutoConfig();
        
        // data mappings
        var configurator = new PocoExportConfigurator<PocoOne>("OneSheet", "One");

        Expression<Func<PocoOne, int>> refId = o => o.Id;
        Expression<Func<PocoOne, DateTime>> refDateTime = o => o.DateTime;
        Expression<Func<PocoOne, IList<double?>>> refCollection = o => o.Values;
        // calculated column
        Expression<Func<PocoOne, string>> refJoinedCollection = o => o.Values != null ? string.Join(",", o.Values.Select(e => e.ToString())) : null;

        configurator
            .AddColumn(refId)
            .AddColumn(refDateTime)
            .AddColumn(refJoinedCollection, "Joined Values");

        // will produce 5 columns for 5 of the first elements of the list, named 'Values[<index>]'
        configurator.AddCollectionColumns(refCollection, 5);

        dataSetExportConfig.AddSheet(configurator.Config);

        // data to be exported
        var dataSet = new DataSetAdapter();
        var data1 = Enumerable.Range(0, 100)
            .Select(i => new PocoOne(6))
            .ToList();

        dataSet.Add(data1, "One");

        // exporter has data mappings and formatting settings
        var exporter = new DataSetToWorkbookExporter(dataSetExportConfig) {DataSet = dataSet};

        exporter.Export(package);

        package.Save();
        // exporter and data mappings can be reused for other data sets

POCO readers can convert column values:

    public class PocoOneReader : TableMappingReader<PocoOne>
    {
        /// <inheritdoc />
        public PocoOneReader()
        {
            Map(o => o.Id);
            Map(o => o.DateTime);
            Map(o => o.Values, "Joined Values", ParseJoinedValues);
        }

        private double?[] ParseJoinedValues(object joinedValue)
        {
            return joinedValue
                ?.ToString()
                .Split(',')
                .Select(Parse)
                .ToArray();
        }

        private static double? Parse(string value)
        {
            if (string.IsNullOrEmpty(value))
                return null;

            return double.Parse(value);
        }
    }

Easy export from ADO.NET:


    var dataSet = new DataSet();
    // ...
    var config = new DataSetExportAutoConfig(dataSet);

    var exporter = new DataSetToWorkbookExporter(config) {DataSet = new DataSetAdapter(dataSet)};

    using(var package = new ExcelPackage(new FileInfo("c:\\output.xlsx")))
    {
        exporter.Export(package);
        package.Save();
    }

Supports reflection for difficult situations:

    configurator.AddColumn<int?>(nameof(PocoTwo.FieldInt), "Reflected Field");

Mappings for base classes can be encapsulated and reused with generics and inheritance (see wiki for more details). Export:

    public class PocoBaseExportConfigurator<T> : PocoExportConfigurator<T>
        where T: PocoBase
    {
        public PocoBaseExportConfigurator(string sheetName, string dataTableName)
            : base(sheetName, dataTableName)
        {
            AddColumn(o => o.Id);
            AddColumn(o => o.DateTime);
        }
    }

    public class PocoOneExportBaseConfigurator<T> : PocoBaseExportConfigurator<T>
        where T: PocoOne
    {
        public PocoOneExportBaseConfigurator(string sheetName, string dataTableName)
            : base(sheetName, dataTableName)
        {
            AddColumn(o => o.Values != null ? string.Join(",", o.Values.Select(e => e.ToString())) : null, "Joined Values");
            AddCollectionColumns(o => o.Values, 5, "value#{0}");
        }
    }

Import:

    public class PocoOneBaseReader<T> : TableMappingReader<T>
        where T: PocoOne
    {
        public PocoOneBaseReader()
        {
            Map(o => o.Id);
            Map(o => o.DateTime);
        }
    }

    public class PocoTwoReader : PocoOneBaseReader<PocoTwo>
    {
        public PocoTwoReader()
        {
            Map(o => o.IntegerFromPocoTwo);
        }
    }

Supports sparse columns and custom placement (see also corresponding test):

    var exportConfig = new PocoThreeExportConfigurator(sheetName).Config;

    const int firstColumnIndex = 2;
    // this is index of the header row
    const int firstRowIndex = 3;

    exportConfig.LeftSheetColumnIndex = firstColumnIndex;
    exportConfig.TopSheetRowIndex = firstRowIndex;
    // no freezing panes
    exportConfig.FreezeColumnIndex = null;

    // move third column to the right
    var movedColumnConfig = exportConfig.GetAutoColumnConfig(exportConfig.Columns[2].Caption);
    movedColumnConfig.Index = exportConfig.Columns.Count + 2;
    // allow it to grow more at the end of the table
    movedColumnConfig.MaximumWidth = 300;

    // ...
    var columnReadingMap = exportConfig.Columns
        .Select(c => new KeyValuePair<string, int>(c.Caption, firstColumnIndex + c.Index))
        .ToList();

    const int startDataRowIndex = firstRowIndex + 1;
    var reader = new ExcelTableReader(workbook.Workbook.Worksheets[1], startDataRowIndex, null, columnReadingMap);
    var readPocos = new PocoThreeReader().Read(reader);

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 115 6/27/2025
1.0.6 722 11/11/2024
1.0.5 3,105 1/21/2020
1.0.4 2,126 3/12/2019
1.0.3-rc 1,624 2/14/2018
1.0.2 2,049 2/9/2018
1.0.1 1,954 2/3/2018
1.0.0 1,942 2/2/2018

Add convenience method PocoExportConfigurator<>.AddColumnCompiled to incrementally/fluently add POCO columns with lambda value extractor (compiled).