Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Support DescriptionAttribute on enum values #602

Open
Jalalx opened this issue Jan 5, 2020 · 0 comments
Open

Support DescriptionAttribute on enum values #602

Jalalx opened this issue Jan 5, 2020 · 0 comments

Comments

@Jalalx
Copy link

Jalalx commented Jan 5, 2020

Hello

EPPlus doesn't consider DescriptionAttribute when extracting enum values.
For example:

using OfficeOpenXml;
using OfficeOpenXml.Table;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;

namespace EPPlusEnum
{
    class Program
    {
        public enum Gender
        {
            [Description("He")]
            Male,

            [Description("She")]
            Female
        }

        public class Person
        {
            [Description("Full Name")]
            public string Name { get; set; }

            [Description("Pronoun")]
            public Gender Gender { get; set; }
        }


        static void Main(string[] args)
        {
            var people = new List<Person>()
            {
                new Person { Name = "Elon Musk", Gender= Gender.Male },
                new Person { Name = "Ada Lovelace", Gender= Gender.Female },
                new Person { Name = "Dennis Ritchie", Gender= Gender.Male },
                new Person { Name = "Maryam Mirzakhani", Gender= Gender.Female },
            };

            using (var package = new ExcelPackage(new MemoryStream()))
            {
                var sheet = package.Workbook.Worksheets.Add("sheet");
                sheet.Cells["A1"].LoadFromCollection(people, true, TableStyles.Dark1);


                Console.WriteLine(sheet.Cells["A1"].Value);
                Console.WriteLine(sheet.Cells["B1"].Value);

                Console.WriteLine(sheet.Cells["A2"].Value);
                Console.WriteLine(sheet.Cells["B2"].Value);

                Console.WriteLine(sheet.Cells["A3"].Value);
                Console.WriteLine(sheet.Cells["B3"].Value);

                Console.WriteLine(sheet.Cells["A4"].Value);
                Console.WriteLine(sheet.Cells["B4"].Value);

                Console.WriteLine(sheet.Cells["A5"].Value);
                Console.WriteLine(sheet.Cells["B5"].Value);
            }


            Console.ReadKey();
        }
    }
}

Expected output:

Full Name
Pronoun
Elon Musk
He
Ada Lovelace
She
Dennis Ritchie
He
Maryam Mirzakhani
She

Actual output:

Full Name
Pronoun
Elon Musk
Male
Ada Lovelace
Female
Dennis Ritchie
Male
Maryam Mirzakhani
Female

I am using EPPlus 4.5.3.2 on .NET Core 2.2

Do you accept a pull request that adds this feature?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant