Comment set Column Type when using EPPlus

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment set Column Type when using EPPlus

Message par ForumBot »

I’m using EPPlus to generate Excel files, in DAL I’m populating DataTable, filling data into table, and passing table to Presentation Layer. From there I’m using LoadFromDataTable() method to generate Excel file.


Everything works fine, except that I want to set one of the column’s type to Date. I tried to set Column type of my DataTable toDate and than pass DataTable to Presentation Layer, but it seems EPPlus either, ignored it, or didn’t recognize, because when I’m opening generated Excel file, cell’s type is Number.


If I manually Format Cells and set Type to Date, Excel shows correct dates. So how can I achieve this ?

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Comment set Column Type when using EPPlus

Message par ayi »

You do need the DataTable column to have the right type but you also need to modify the column or cell’s Style.Numberformat.Format property.


Say you have an ExcelWorksheet named ws:


ws.Column(1).Style.Numberformat.Format  = "yyyy-mm-dd"; 
//OR "yyyy-mm-dd h:mm" if you want to include the time!

Répondre

Revenir à « Excel & VBA »