EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

EpplusNestedTableColumn attribute with EpplusTableColumn atrribute in nested class

Open AwkEng opened this issue 3 years ago • 2 comments
trafficstars

I've been experimenting with the new attributes from OfficeOpenXml.Attributes and ran into an issue. When I use a complex type with a child class which also uses the EpplusTableColumn attribute, the 'HeaderPrefix' text is not included in the child member's header name. Rather, it only uses the child's member header name.

I grabbed the following example from TestClasses.cs. For the member 'CollateralOwner.WWID', I would expect the header name to be "Collateral Owner World Wide ID", however, it is returning "World Wide ID" only.

    [
    EpplusTable(AutofitColumns = true, PrintHeaders = true, TableStyle = TableStyles.Medium2),
    EPPlusTableColumnSortOrder(Properties = new string[] {
        nameof(PlatformName), nameof(PchDieName), nameof(OtherDieName), nameof(Stepping), nameof(MilestoneDay),
        nameof(CollateralOwner), nameof(MissionControlLead), nameof(CreatedUtc), nameof(ModifiedUtc)
    })
    ]
    public class IntegratedPlatformExcelRow
    {
        [EpplusNestedTableColumn(HeaderPrefix = "Collateral Owner")]
        public WorkerDTO CollateralOwner { get; set; }

        [EpplusTableColumn(Header = "Created (GMT)", NumberFormat = "yyyy-MM-dd HH:MM")]
        public DateTime CreatedUtc { get; set; }

        [EpplusTableColumn(Header = "Milestone Day")]
        public string MilestoneDay { get; set; }

        [EpplusNestedTableColumn (HeaderPrefix = "Mission Control Lead")]
        public WorkerDTO MissionControlLead { get; set; }

        [EpplusTableColumn(Header = "Modified (GMT)", NumberFormat = "yyyy-MM-dd HH:MM")]
        public DateTime ModifiedUtc { get; set; }

        [EpplusTableColumn(Header = "SOC/CPU Die Name")]
        public string OtherDieName { get; set; }

        [EpplusTableColumn(Header = "PCH Die Name")]
        public string PchDieName { get; set; }

        [EpplusTableColumn(Header = "Product Family")]
        public string PlatformName { get; set; }

        public string Stepping { get; set; }
    }

    [EPPlusTableColumnSortOrder(Properties = new string[] { nameof(Name), nameof(Email), nameof(WWID) })]
    public sealed class WorkerDTO
    {
        [EpplusIgnore]
        public bool Active { get; set; }

        [EpplusTableColumn(Header = "Email")] <---I added this attribute
        public string Email { get; set; }

        [EpplusTableColumn(Header = "Name")] <---I added this attribute
        public string Name { get; set; }

        [EpplusTableColumn(Header = "World Wide ID")] <---I added this attribute
        public int WWID { get; set; }
    }

I put together a solution that modifies the SetupInternal() and SetHeaders() methods, if you would like me to submit a PR.

AwkEng avatar Aug 28 '22 22:08 AwkEng

Hi,

Thanks for reporting this. I'll have a closer look at it tomorrow.

If you want to submit a PR, see our Contributing guidelines. If your contribution is less than 20 lines of code (tests are not included), you can just add it, set our develop branch as target.

swmal avatar Aug 29 '22 14:08 swmal

I had a look at this, it seems to work as long as you don't have a EpplusTableColumn attribute on the WorkerDTO, but when you add this the HeaderPrefix is ignored. It should be a simple fix so I'll fix it during the day so we can get it out in the new version that we will release today or tomorrow.

swmal avatar Aug 30 '22 09:08 swmal

After testing, as of the current version (6.2.8) this issue appears to fixed.

c3hb avatar Sep 01 '23 16:09 c3hb