Skip to content

Export objects to excel, including adding title rows with filtering.

License

Notifications You must be signed in to change notification settings

bchristie/ExcelExporter

Repository files navigation

ExcelExporter

Simple Object to Excel exporter.

Synopsis

I needed a way to take a single object and an Enumerable of objects and dumpt them in to excel. I also needed the data to stay preserved in a way that Excel didn't ruin fields with its content detection. For example, under normal circumstances exporting an object as a CSV that contains "00123" would be observed in Excel as simply the number "123"; I just couldn't have that.

Solution

To preserve information, this parser uses a coupling of reflection to know column titles (object properties become titles) and an ExcelColumnAttribute decorator for further customization. e.g.

class Invoice
{
    [ExcelColumn("Invoice", ExcelColumnFormat.Text)]
    public String InvoiceId { get; set; }

    [ExcelColumn("Amount Due", ExcelColumnFormat.Currency)]
    public Double Amount { get; set; }
}

Resulting in something similar to:

InvoiceAmount Due
00123 $1,024.99  
00124 $2,048.99  
00125 $4,096.99  

About

Export objects to excel, including adding title rows with filtering.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages