.Net Export DataTable To Excel XLSX /PDF

Last week we had a meeting other friends at work, they has some ideas about the enhancement of the in-house application. E.g. export the data from the in-house application to Spreadsheet, which would be very handy when you need to keep a record of the query you done or need to email the data to the client…etc. I have spent sometime in the weekend and see how to achieve that. finally, I have created a simple library to Export DataTable/ DataGridView / Grid View to Excel XLSX or PDF format.

Here is my .Net Library: “ShareChiWaiLib” at the moment it only has 1 class “XLSXHelper“, which allow user to
Export DataTable to Excel XLSX or PDF
By using XLSXHelper. ExportDataTableToXLSX() method

Export DataGridView to Excel XLSX or PDF
By using XLSXHelper. ExportDataGridViewToXLSX() method

Export GridView to Excel XLSX or PDF
By using XLSXHelper. ExportGridViewToXLSX() method

Here it is the description about this class.

Imports ShareChiWaiLib

Public sub Example()
XLSXHelper.ExportDataGridViewToXLSX(“DataGridView Name”,
“True/False — whether to includes the column header”,
“FileType — is ENUM E.g. ExportFileType.XLSX to Export XLSX Format in Excel 2007/2010
ExportFileType.PDF is for PDF Format”,
“FilePath — where you want the file export to and please ensure you have premission to write to that directory,
“FileName – Filename includes file Extension E.g. ‘.xlsx’ or ‘.pdf'”

‘are similar, therefore I will leave it to you to find out =)

End Sub

Feel Free to download the Library from the URL below.
.Net 2.0
.Net 3.5
.Net 4.0

If you do not have office in you computer, you may need to download Office Primary Interop Assemblies, in order to get it work

Office 2007

I will try to put more feature, useful stuff on “ShareChiWaiLib” in future. I would be grateful, if you could give me some suggestion/feedback about ShareChiWaiLib and  what to put in future=).

Hope you find it useful

Leave a Reply