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.
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.
Step 2: Select data source from the database
Choose data source from the database. It may be a table, a view or SQL Command. Here we list two styles.
Data source from table:
Data source from SQL Command:
Step 3: Select columns
After selecting a Table, View or SQL Command, it will display all columns of it. If you don’t need all of the data in it, you may select columns of it. Just choose some of them you need.
Step 4: Specify a file format and Save
The last step is to show your data result with a specified file format. In the component, many formats are supported, such as XLS, PDF, MS Word, HTML, MS clipboard, XML and so on. And you may give a path to save the file.
Use the Component
Parameter | Value |
Database | Choose one or add one unlisted |
Data source | Table, View or SQL Command |
Columns | Select columns to export |
Export format | Possible values: XLS, PDF, MS Word, HTML, MS clipboard, XML and so on |
Save path | Select a local path |
Supported Database
If we have a database-provider, DataExportWizard could support any database. Editing the App.config file can add other database providers. All installed providers that implement System.Data.Common.DbProviderFactory will be automatically filled in the Database-Provider list of the first step.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.data>
<DbProviderFactories>
<add name="SqlClient Data Provider"
invariant="System.Data.SqlClient"
description=".Net Framework Data Provider for SqlServer"
type="System.Data.SqlClient.SqlClientFactory, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OLE DB Data Provider"
invariant="System.Data.OleDb"
description=".Net Framework Data Provider for OLE DB"
type="System.Data.OleDb.OleDbFactory, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</DbProviderFactories>
</system.data>
</configuration>
Conclusion
In this method, we use a free data export component. You may download it here.
发表评论
5exoup Thanks for the article post.Really looking forward to read more. Really Cool.
gJY8rD Very good article. I am facing some of these issues as well..
ydg7xX Thanks for the blog article.Thanks Again. Want more.
eesHOo Major thankies for the article.Much thanks again.