EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

LoadFromDataTable Add data type detection For Excel Range

Open minren118 opened this issue 2 years ago • 2 comments

Currently exporting Excel data, NumberFormat of Excel cell range is not set based on data type of DataTable

image

It is recommended to add the ability to specify Excel Range NumberFormat based on the DataTable data type, especially long integer fields. If String is specified in the DataTable and can be exported, NumberFormat is automatically set to "@" before exporting, so that the numbers can be displayed completely.

minren118 avatar May 18 '23 08:05 minren118

You can set number formats via attributes if desired...https://github.com/EPPlusSoftware/EPPlus/wiki/LoadFromCollection-using-Attributes. As we don't know what the desired number formats is from the data type, we can not set it that way.

JanKallman avatar May 19 '23 06:05 JanKallman

You're right, but if you still want to use LoadFromDataTable to do a lightweight export instead of defining a class that has specific definitions,

one of the biggest problems with the DataTable right now is that it's a text type. If I just let Excel determine the data type, it's easy to lose precision with long integer numbers.

I think I can rely on EPPLUS to convert the corresponding column to text type, Numberformat to @, when I finally write to Excel cells with a text type defined in the DataTable.

minren118 avatar May 19 '23 06:05 minren118