ExcelMapper
ExcelMapper copied to clipboard
ExcelMapper always generate extra columns
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; }
}
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");
You can remove all mappings like so:
var typeMapper = mapper.TypeMapperFactory.Create(typeof(Dto));
typeMapper.ColumnsByName.Clear();