News Category

Datatable Export

Datatable Export (9)

The aim of the article is to introduce the procedure of exporting data into Office OpenXML in only two steps with a .net component. Spire.DataExport is a completely pure .NET component suit for exporting data into MS Excel, MS Word, HTML, Office OpenXML, PDF, MS Access, DBF, RTF, SQL Script, SYLK, DIF, CSV, MS Clipboard format. It has high performance for exporting data from Command, ListView, DataTable components, which help you to save much time and money.

Please download Spire.DataExport for .NET, add Spire.DataExport.dll as reference and set its target framework as .NET 4. Besides, many developers also check and download another C# excel component together - Spire.XLS for .NET.

Step1: Function to fill data in datatable

In this step, Spire.DataExport will help to load Data information from the datatable. After setting up the data source and SQL command, we can even preview and modify data through DataGridVew before exporting.

[C#]
private void Form1_Load(object sender, EventArgs e)
        {
            oleDbConnection1.ConnectionString = txtConnectString.Text;
            oleDbCommand1.CommandText = txtCommandText.Text;
            using (OleDbDataAdapter da = new OleDbDataAdapter())
            {
                da.SelectCommand = oleDbCommand1;
                da.SelectCommand.Connection = oleDbConnection1;
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
            }
        }

Check the Screenshot below:

Datatable_to_XML_01

Step2: Export Data to Office OpenXML

The code below shows how to export data from the datatable to Office OpenXML. Spire.DataExport will create a new Office OpenXML and export data into Office OpenXML through DataGridView. It also allows you to rename the generated Office OpenXML in this step.

[C#]
private void btnExportToXml_Click(object sender, EventArgs e)
        {
            Spire.DataExport.XML.XMLExport xmlExport = new Spire.DataExport.XML.XMLExport();
            xmlExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            xmlExport.DataTable = this.dataGridView1.DataSource as DataTable;
            xmlExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            xmlExport.FileName = @"..\..\ToXml.xml";
            xmlExport.SaveToFile();
        }

Check the Screenshot below:

Datatable_to_XML_02

This article will show you a clear introduction of how to Export Data to MS Access in C# via a .NET Data Export component. Spire.DataExport for.NET is designed to help developers to perform data exporting processing tasks. With Spire.DataExport, the whole exporting process is quickly and it only needs two simple steps.

Please download Spire.DataExport for .NET and install it on your system, add Spire.DataExport.dll as reference in the downloaded Bin folder thought the below path: “…\Spire.DataExport\Bin\NET4.0\ Spire.DataExport.dll”.

Step 1: Load Data Information

In this step, Spire.DataExport helps us load data from database. Through DataGridVew, we can even preview and modify data.

[C#]
private void Form1_Load(object sender, EventArgs e)
        {
            oleDbConnection1.ConnectionString = txtConnectString.Text;
            oleDbCommand1.CommandText = txtCommandText.Text;
            using (OleDbDataAdapter da = new OleDbDataAdapter())
            {
                da.SelectCommand = oleDbCommand1;
                da.SelectCommand.Connection = oleDbConnection1;
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
            }
        }

Please check the screenshot:

datatable to access

Step 2: Set Export into MS Access

Here we need to set it as Access format. Spire.DataExport will create a new Access and through DataGridView export data into Access file. You can rename the file as you like.

[C#]
private void btnExportToAccess_Click(object sender, EventArgs e)
        {
            Spire.DataExport.Access.AccessExport accessExport = new              
            Spire.DataExport.Access.AccessExport();
            accessExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            accessExport.DataTable = this.dataGridView1.DataSource as DataTable;
            accessExport.DatabaseName = @"..\..\ToMdb.mdb";
            accessExport.TableName = "ExportFromDatatable";
            accessExport.SaveToFile();
        }

Here comes to the results:

Export to Access

There are some requirements to export datatable or dataset to word file on many occasions at work. The aim of this article is to help you complete this requirement. Spire.DataExport can help easily load data from the datatable and create a new Word file for storing the data. In addition to this, Spire.DataExport (or Spire.Office) can export data into MS Excel, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV and MS Clipboard format as well, which can be downloaded here. The following code is the example of showing how Spire.DataExport works.

Step 1: Function to fill data in datatable

In this step, Spire.DataExport will help load Data information from the datatable. After setting up the data source and SQL command, it allows you to preview and edit data in DataGridView component before exporting.

[C#]
private void Form1_Load(object sender, EventArgs e)
        {
            oleDbConnection1.ConnectionString = txtConnectString.Text;
            oleDbCommand1.CommandText = txtCommandText.Text;
            using (OleDbDataAdapter da = new OleDbDataAdapter())
            {
                da.SelectCommand = oleDbCommand1;
                da.SelectCommand.Connection = oleDbConnection1;
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
            }
        }

Effect Picture

datatable to word

Step 2: Export Data to word document

The code below shows how to export data from the datatable to Word file. Spire.DataExport will create a new MS Word for storing exported Data. It also allows you to rename the generated Word file in this step.

[C#]
private void btnExportToWord_Click(object sender, EventArgs e)
        {
            Spire.DataExport.RTF.RTFExport rtfExport = new Spire.DataExport.RTF.RTFExport();
            rtfExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            rtfExport.DataTable = this.dataGridView1.DataSource as DataTable;
            rtfExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            RTFStyle rtfStyle = new RTFStyle();
            rtfStyle.FontColor = Color.Blue;
            rtfStyle.BackgroundColor = Color.LightGreen;
            rtfExport.RTFOptions.DataStyle = rtfStyle;
            rtfExport.FileName=@"..\..\ToWord.doc";
            rtfExport.SaveToFile();
        }

Effect Picture

datatable to word

Why Export Datatable to RTF?

RTF is a Microsoft specification and certified file format used with DOC and DOCX. It is a core part of the Microsoft Office system. RTF usually used for cut and paste, including paste special and used when opening documents into Word. RTF does not cause document corruption.

RTF allows Workshare tremendous flexibility in successfully translating between any number of document types because of its ubiquity. Workshare products can not only maintain document fidelity, but provide portability advantages when moving around different Microsoft Word systems, or translating to other document types.

How to Export DataTable to RTF through DataGridView?

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to RTF exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which is about to be exported out.

[C#]
        private void btnLoad_Click(object sender, EventArgs e)
        {
            oleDbConnection.ConnectionString = this.textBox1.Text;
            OleDbCommand oleDbCommand = new OleDbCommand();
            oleDbCommand.CommandText = this.textBox2.Text;
            oleDbCommand.Connection = oleDbConnection;
            using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
            {
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
            }
        }

Effect Screenshot

Datatable to RTF

Step 2: Set Export into RTF

Spire.DataExport allows user to export data into most popular file formats including MS Excel, RTF, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as RTF format. Spire.DataExport will create a new RTF file and through DataGridView export data into RTF file. You also can rename the file as you like.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.RTF.RTFExport RTFExport = new Spire.DataExport.RTF.RTFExport();
            RTFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            RTFExport.DataTable = this.dataGridView1.DataSource as DataTable;
            RTFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            RTFExport.FileName = "RTF0722.rtf";
            RTFExport.SaveToFile();
        }

Effect Screenshot

Datatable to RTF

When we export data out from Database we may have requirements of exporting data from Datatable to CSV because CSV is a simple file format that is widely supported. CSV (The comma-separated values) file format is a set of file formats used to store tabular data in which numbers and text are stored in plain textual form that can be read in a text editor. Lines in the text file represent rows of a table, and commas in a line separate what are fields in the table row.

Here we mainly discuss how to Export Datatable to CSV with Spire.DataExport for .NET.

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to CSV exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which is about to be exported out.

[C#]
	
private void btnLoad_Click(object sender, EventArgs e)
{
  using (OleDbConnection oleDbConnection = new OleDbConnection())
  {
    oleDbConnection.ConnectionString = this.textBox1.Text;
    OleDbCommand oleDbCommand = new OleDbCommand();
    oleDbCommand.CommandText = this.textBox2.Text;
    oleDbCommand.Connection = oleDbConnection;
    using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
      {
      DataTable dt = new DataTable();
      da.Fill(dt);
       dataGridView1.DataSource = dt;
      }
  }
}

Effect Screenshot

Datatable to CSV

Step 2: Set Export into CSV

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as CSV format. Spire.DataExport will create a new CSV file and through DataGridView export data into CSV file. You also can rename the file as you like.

[C#]
private void btnRUN_Click(object sender, EventArgs e)
{
  TXTExport CSVExport = new TXTExport();
  CSVExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
  CSVExport.DataTable = this.dataGridView1.DataSource as DataTable;
  CSVExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
  CSVExport.FileName = "CSV0721.csv";
  CSVExport.SaveToFile();
}

Effect Screenshot

Datatable to CSV

DBF is a format created by Ashton-Tate and can be recognized by ACT, Lipper, FoxPro, Arago, Wordtech, Xbase and other programs related with Database. Although MS Excel has been the most popular data form software application, DBF format data form files still used widely. So sometimes we may have requirements to export data from datatable to DBF. And with Spire.DataExport, we can export datatable to DBF through DataGridView effortlessly!

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to DBF exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which are about to be exported out.

[C#]
	
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OleDbConnection oleDbConnection = new OleDbConnection())
            {
                oleDbConnection.ConnectionString = this.textBox1.Text;
                OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.CommandText = this.textBox2.Text;
                oleDbCommand.Connection = oleDbConnection;
                using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
            }
        }

Effect Screenshot

Datatable to DBF

Step 2: Set Export into DBF

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as DBF format. Spire.DataExport will create a new DBF file and through DataGridView export data into DBF file. You also can rename the file as you like.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.DBF.DBFExport DBFExport = new Spire.DataExport.DBF.DBFExport();
            DBFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            DBFExport.DataTable = this.dataGridView1.DataSource as DataTable;
            DBFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            DBFExport.FileName = "DBF0401.dbf";
            DBFExport.SaveToFile();
        }
          

Effect Screenshot

Datatable to DBF

How to Export DataTable to PDF

2011-07-20 05:44:03 Written by support iceblue

This article will show you how to use Spire.DataExport to Export Datatable to PDF through DataGridView. Through DataGridView, users can preview data information and modify the information if they think it’s not correct before exporting data. With Spire.DataExport, this whole exporting process could be fast and easy.

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to PDF exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which is about to be exported out.

[C#]
	
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OleDbConnection oleDbConnection = new OleDbConnection())
            {
                oleDbConnection.ConnectionString = this.tbCS.Text;
                OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.CommandText = this.tbCT.Text;
                oleDbCommand.Connection = oleDbConnection;
                using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView.DataSource = dt;
                }
            }
        }
   

Effect Screenshot

Datatable to PDF

Step 2: Set Export into PDF

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as PDF format. Spire.DataExport will create a new PDF file and through DataGridView export data into PDF file. You also can rename the file as you like.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
            PDFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            PDFExport.DataTable = this.dataGridView.DataSource as DataTable;
            PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            PDFExport.SaveToFile("20110223.pdf");

        }

Effect Screenshot

Datatable to PDF

Spire.DataExport supports exporting data from DataTable into HTML. HTML (HyperText Markup Language) is a language for describing web pages. HTML documents are also called web pages which contain HTML tags and plain text. Use Spire.DataExport exporting DataTable to HTML to share your data on internet.

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to HTML exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which are about to be exported out.

[C#]
	
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OleDbConnection oleDbConnection = new OleDbConnection())
            {
                oleDbConnection.ConnectionString = this.tbCS.Text;
                System.Data.OleDb.OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.CommandText = this.tbCT.Text;
                oleDbCommand.Connection = oleDbConnection;
                using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
            }
        }
   

Effect Screenshot

DataTable to HTML

Step 2: Set Export into HTML

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as HTML format. Spire.DataExport will create a new HTML file and through DataGridView export data into HTML file. You also can rename the file as you like.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.HTML.HTMLExport HTMLExport = new Spire.DataExport.HTML.HTMLExport();
            HTMLExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            HTMLExport.DataTable = this.dataGridView1.DataSource as DataTable;
            HTMLExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            HTMLExport.SaveToFile("20110223.html");
        }  

Effect Screenshot

DataTable to HTML

Export DataTable to Excel can be very easy through Spire.DataExport (or Spire.Office). Furthermore, Spire.DataExport enables user to Export data to Excel through DataGridView. Through DataGridView users can preview and modify data information before exporting.

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to Excel exporting process.

Step 1: Load Data Information

In this step, Spire.DataExport will help you load Data information from your datatable. After you put in your data source and SQL command, you can preview and modify data information in DataGridView area.

[C#]
	
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using(OleDbConnection oleDbConnection = new OleDbConnection())
            {
                oleDbConnection.ConnectionString = this.textBox1.Text;
                OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.CommandText = this.textBox2.Text;
                oleDbCommand.Connection = oleDbConnection;
                using(OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
            }
        } 

   

Effect Screenshot

DataTable to Excel

Step 2: Set Export into Excel

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Now, in this step you should give an order to Export Data into Excel file format. Spire.DataExport will create a new MS Excel Worksheet for storing Data which exported out. You can rename the excel file in this step either.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.XLS.CellExport cellExport = new Spire.DataExport.XLS.CellExport();
            Spire.DataExport.XLS.WorkSheet worksheet1 = new Spire.DataExport.XLS.WorkSheet();
            worksheet1.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            worksheet1.DataTable = this.dataGridView1.DataSource as DataTable;
            worksheet1.StartDataCol = ((System.Byte)(0));
            cellExport.Sheets.Add(worksheet1);
            cellExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView; 
            cellExport.SaveToFile("20110223.xls");
        }
       

Effect Screenshot

DataTable to Excel