AO.EPPlusFree 1.0.0

dotnet add package AO.EPPlusFree --version 1.0.0
NuGet\Install-Package AO.EPPlusFree -Version 1.0.0
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="AO.EPPlusFree" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AO.EPPlusFree --version 1.0.0
#r "nuget: AO.EPPlusFree, 1.0.0"
#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.
// Install AO.EPPlusFree as a Cake Addin
#addin nuget:?package=AO.EPPlusFree&version=1.0.0

// Install AO.EPPlusFree as a Cake Tool
#tool nuget:?package=AO.EPPlusFree&version=1.0.0

About

Nuget package with extension methods for retrieving data as typed objects from Excel using EPPlusFree.

How to use

Import AO.EPPlusFree as a using in your class.

For retrieving a single item from the second row or column: worksheet.GetItem<MyItem>(2);

For retrieving all items: worksheet.GetItems<MyItem>();

Above methods also accept your own custom mapping.

There are 3 ways of determening the mapping used:

  1. By use of attributes
  2. Automatically based on the header row
  3. By specifying your own mapping

Mappings based on attributes

Decorate your own item class with attributes.

[ExcelMapper(Header = 0)]
public class MyItem
{
    [ExcelMap(Column = 1)]
    public string Name { get; set; }
    
    [ExcelMap(Column = 2)]
    public int Age { get; set; }
}

This will map each row to MyItem where the first column is mapped to the Name property and the second column to the Age property.

[ExcelMapper(MappingDirection = ExcelMappingDirectionType.Vertical, Header = 0)]
public class MyItem
{
    [ExcelMap(Row = 1)]
    public string Name { get; set; }
    
    [ExcelMap(Row = 2)]
    public int Age { get; set; }
}

This will map each column to MyItem with the first row to the Name property and the second row to the Age property.

Mappings based on the header row

The default will be Horizontal mapping where the Header row is the first row in the sheet. You can override this by applying the ExcelMapper attribute to your item.

[ExcelMapper(MappingDirection = ExcelMappingDirectionType.Vertical, Header = 2)]
public class MyItem
{
    public string Name { get; set; }
    
    public int Age { get; set; }
}

This will map columns to MyItem based on a mapping created by the headers in the second column.

Specifying your own mapping

Lastly you can create your own mapping by inheriting from ExcelMap<TItem> and supplying it as a parameter to the GetItem/GetItems methods.

public class MyMap : ExcelMap<MyItem>
{
    protected override ExcelMappingDirectionType MappingDirection => ExcelMappingDirectionType.Vertical;
    
    protected override int Header => 0;
    
    public static MyMap Create()
    {
        var map = new MyMap();
        
        var type = typeof(MyMap);
        map.Mapping.Add(1, type.GetProperty(nameof(MyItem.Name)));
        map.Mapping.Add(2, type.GetProperty(nameof(MyItem.Age)));
        
        return map;
    }
}

This will map columns to MyItem where the first row is matched to the Name property and the second row to the Age property. Next you'll need to supply the mapping to the item retrieval functions.

var myMap = MyMap.Create();

var myItem = worksheet.GetItem(2, myMap);
var myItems = worksheet.GetItems(myMap);

For an in depth explanation of the code you can read my original article here: https://www.codeproject.com/Articles/1202924/Simple-POCO-Mapper-for-EPPlus

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.0 235 11/17/2023