Handle datetime display for excel columns

Photo from: https://www.syncfusion.com/blogs/post/6-easy-ways-to-export-data-to-excel-in-c-sharp.aspx

Background

Suppose we got below class object:

public class Customer
{
public string ID{ get; set; }
public string Sex { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public DateTime CreateDate { get; set; }
}

We would like to export above structure as below example of excel document.

Example of excel

We could use EPPlus package for .NET Core that help us dynamic creating excel document for just few lines of code block:

The key of how to dynamic was introduced method: LoadFromCollection that help us handle diverse class objects (Customer/Order…) and no need create additional template(s) anymore:)

So far everything would be perfect but the Column: CreateDate looks a little wire. The original “DateTime” for excel was treat as data type as number. But it was not easy for human to understand the meaning of the column.

The ideal here was we could found out the sequence number of data type “DateTime”. Then we could force to style the display format of those “DateTime” column(s) more human readable. The completed code example please refer to below Gist example.

After we adjust the style of the “DateTime” column(s). The content of excel should looks like below. If you got better ideal for handling this kind of cases, please fell free to write down under the bulletin board😊.

Human readable excel format for column: CreateDate

Reference

--

--

--

Coding for fun

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Key Elements of NFT Evaluation Value_Storage Mechanism

https://youtu.be/AacvTY6gWcQ

Arbitrum Odyssey Voting Update

Sudoku Solver Using Backtracking in Python

Example- Unsolved Sudoku

Enhance Your User Experience with Machine Learning

How to Perform Bond Valuation with Python

GXChain Progress Report Oct.26-Nov.1

Scaling Featuretools with Dask

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
LAI TOCA

LAI TOCA

Coding for fun

More from Medium

AlterNET Studio 8.0 released — now with support for Visual Studio 2022 and .NET 6

Custom Driver Command Executor

Selenium Logo with C# Logo

C#/VB.NET: Delete Blank Cells, Rows and Columns in Excel

Backup and Restore PostgreSQL database (.sql) using C# .NET