mganss / ExcelMapper

An Excel to object mapper. Maps POCOs to and from Excel. Configuration via convention, attributes, or fluent methods.
MIT License
793 stars 122 forks source link

How to map an image property? #297

Closed LJN-hzleaper closed 7 months ago

LJN-hzleaper commented 7 months ago

My dto has a image property, for example a WPF BitmapImage property, how to map it to a excel column? I have tried following code, but it didn't work.

ExcelMapper mapper = new();
mapper.AddMapping(typeof(Dto), "Image", nameof(Dto.Image));
mapper.Save("E:/Test.xlsx", GetData(), "Hi");

public class Dto
{
    public BitmapSource Image
    {
        get=> new BitmapImage(new Uri("E:/1.png")); 
        set{}
    } 

    public int Id { get; set; }

    public string? Name { get; set; }
}
mganss commented 7 months ago

There is no builtin support for images yet. But you can try custom mapping.

mganss commented 7 months ago

It seems images in Excel are not actually cell contents so this will probably not be easy: https://stackoverflow.com/a/61442249/1970064