Thursday, March 03, 2011

Data Export from Database to Excel, PDF and Word for .NET without Automation and Acrobat Reader

Introduction
This article introduces how to export data from database to Excel, PDF, MS Word, HTML, MS clipboard ,XML, DBF, SQL Script, SYLK, DIF, CSV without Automation and Acrobat Reader, you just need a free component. In this example, I will show:

Use GetFactoryClasses() method to get all factories.
How to make a connection with database.
How to get data source from database.
How to export the data source from database.
How to export the data to many formats.(Word, Excel, PDF...)

Background
For a programmer, in order to export data to a file specified, you don't need to write a plenty of code, you just need to choose a datasource or write a command to select data and specify a file format to show the data.

Four simple steps:
Select a database.(SQL Client, OLE DB)
Select data source from the database.(Table, View and SQL Command)
Select columns as you want to export.
Specify a file format to show the result and save it to a file with the specified format.( XLS, PDF, MS Word, HTML, MS clipboard ,XML, DBF, SQL Script, SYLK, DIF, CSV)

Here, we use step wizard to show you how to do it.

Step 1: Select a database
You may choose a database to export data from. The database may be SQL Client or OLE DB and so on. Then you may create a connection to the database by inputting the connection string.
choose_result_format.png

Read more: Codeproject