Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Cells.InsertDataTable Time values are recognized as String

$
0
0
Hi,

I am using the Cells.InsertDataTable functionality wherein I import a dataTable from a query to a particular worksheet in the Excel file.
        public void ClosedXml(DataTable dt, string usertemplate, string exceltab)
            {
            var workbook = new XLWorkbook(usertemplate);
            var worksheet = workbook.Worksheet(exceltab);
           
            worksheet.Cell("A2").InsertData(dt.AsEnumerable());
            workbook.Save();

            }
But when I opened the Excel file, the results were not the ones I expected.

Image

As you can see, columns P and Q contain integers and thus automatically recognized and has formula that is why they are in the right side of the cell. but columns R to W are time values and therefore are recognized only as strings that is why they are on the left side.

In my previous implementation, I use the QueryTables interface of Excel interop wherein I transfer a CSV file coming from a dataTable to Excel that is why all the cells have formula and are on the right side when I opened the Excel file.

But yeah, Excel Automation using the Interop is not recommended for server-side deployment.

Are there any similar ways to do the same using ClosedXML?

Any ideas are appreciated.

Thanks!

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>