Skip to content

jangocheng/EPPlus.Core.Extensions

 
 

Repository files navigation

EPPlus.Core.Extensions Build status codecov

Installation NuGet version

It's as easy as PM> Install-Package EPPlus.Core.Extensions from nuget

Dependencies

.NET Framework 4.6.1       EPPlus >= 4.1.1

.NET Standard 2.0       EPPlus.Core >= 1.5.4

Documentation and Examples

The project will be documented soon. For now, just look at the test project (EPPlus.Core.Extensions.Tests). It has just enough examples to show you how to use these extension methods.

Basic usage
public class PersonDto
    {      
        [ExcelTableColumn("First name")]
        [Required(ErrorMessage = "First name cannot be empty.")]
        [MaxLength(50, ErrorMessage = "First name cannot be more than {1} characters.")] 
        public string FirstName { get; set; }

        [ExcelTableColumn("Last name")]       
        public string LastName { get; set; }
        
        [ExcelTableColumn(3)]
        [Range(1900, 2050, ErrorMessage = "Please enter a value bigger than {1}")]
        public int YearBorn { get; set; }
        
        public decimal NotMapped { get; set; }
    }
    
// Converting from Excel to list of objects

    // Direct usage: 
        excelPackage.ToList<PersonDto>(configuration => configuration.SkipCastingErrors());

    // Specific worksheet: 
        excelPackage.GetWorksheet("Persons").ToList<PersonDto>();  
    
// From list to Excel package

    List<PersonDto> persons = new List<PersonDto>();

    // Direct usage
        ExcelPackage excelPackage = persons.ToExcelPackage();
        byte[] excelPackageXlsx = persons.ToXlsx();
       
    // With configuration

    List<PersonDto> pre50 = persons.Where(x => x.YearBorn < 1950).ToList();
    List<PersonDto> post50 = persons.Where(x => x.YearBorn >= 1950).ToList();
        
    ExcelPackage excelPackage = pre50.ToWorksheet("< 1950")
                             .WithConfiguration(configuration => configuration.WithColumnConfiguration(x => x.AutoFit()))
                             .WithColumn(x => x.FirstName, "First Name")
                             .WithColumn(x => x.LastName, "Last Name")
                             .WithColumn(x => x.YearBorn, "Year of Birth")
                             .WithTitle("< 1950")
                             .NextWorksheet(post50, "> 1950")
                             .WithColumn(x => x.LastName, "Last Name")
                             .WithColumn(x => x.YearBorn, "Year of Birth")
                             .WithTitle("> 1950")
                             .ToExcelPackage(); 

About

An extensions library for both EPPlus and EPPlus.Core packages to generate and manipulate Excel files easily.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.0%
  • PowerShell 2.0%