Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcelMapper always generate extra columns #298

Open
LJN-hzleaper opened this issue Mar 25, 2024 · 2 comments
Open

ExcelMapper always generate extra columns #298

LJN-hzleaper opened this issue Mar 25, 2024 · 2 comments

Comments

@LJN-hzleaper
Copy link

In my demo app, ExcelMapper always output extra columns that I dont't want. How to prevent it?

        ExcelMapper mapper = new();
        mapper.AddMapping(typeof(Dto), "Identity", nameof(Dto.Id));
        mapper.AddMapping(typeof(Dto), "User Name", nameof(Dto.Name))
            .ToExcelOnly();
        mapper.Save("E:/Test.xlsx", GetData(), "Hi");

public class Dto
{
    public int Id { get; set; }

    public string? Name { get; set; }
}

image

@LJN-hzleaper
Copy link
Author

I can remove these columns one by one from output by Ignore, but is there a batch way?

        ExcelMapper mapper = new();
        mapper.Ignore(typeof(Dto), nameof(Dto.Id));
        mapper.Ignore(typeof(Dto), nameof(Dto.Name));
        mapper.AddMapping(typeof(Dto), "Identity", nameof(Dto.Id));
        mapper.AddMapping(typeof(Dto), "User Name", nameof(Dto.Name))
            .ToExcelOnly();
        mapper.Save("E:/Test.xlsx", GetData(), "Hi");

@mganss
Copy link
Owner

mganss commented Mar 25, 2024

You can remove all mappings like so:

var typeMapper = mapper.TypeMapperFactory.Create(typeof(Dto));
typeMapper.ColumnsByName.Clear();

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

No branches or pull requests

2 participants