0
votes

I have a problem about exporting a datatable to excel. The exporting to excel is not the problem there are enough solutions on stackoverflow and in the internet. My problem is I must export the datatable with the formating. Now when I export the datatable all cells (header and body) are defined as standard (dataformating). So if I export a datatable for example with integer (numbers) and string (text), I will get the right formating in excel integer is formated as number and the string are formated as text (in excel, I mean the category). Does anyone know a solution for this?

At the moment I use the function on http://www.codeproject.com/Tips/406704/Export-DataTable-to-Excel-with-Formatting-in-Cshar to export my datatable.

My second question is. Is there a way to set the styles with a second datatable which contains the whole configure for the tablestyling (headerbackground and so on)

In my function now I configure this with input parameters which set the styles.

This is my thought how it looks like.

ExportDatatabletoExcel(ByVal _datatable as datatable, ByVal _styletable as Datatable)
2

2 Answers

0
votes

This article should be very useful for you: Understanding the Excel Object Model

It contains details and code examples for working with styles through .NET and Excel.

0
votes

You could also use EPPLUS to create real excel documents. It would be more work than outputting HTML as an excel document but would give you more control.

https://epplus.codeplex.com/