Use Visual C #. NET to transfer data to an Excel Workbook
Source: Internet
Author: User
Overview
Automation is the most common technology used to transmit data to an Excel Workbook. With automation, you can call methods and attributes specific to Excel tasks. "Automation" gives you the maximum flexibility to specify the location of data in the workbook, format the workbook, and perform various settings at runtime.
With automation, you can use multiple technologies to transmit data:
•
Transmit data one by one in cells
•
Transfers the data in the array to the area composed of cells.
•
Use the CopyFromRecordset method to transmit data in the ADO record set to the cell area.
•
Create a QueryTable object on an Excel worksheet that contains the query results for the ODBC or OLEDB data source.
•
Transfer data to the clipboard, and paste the clipboard content to the Excel worksheet. You can also use a variety of methods that do not necessarily require "automation" to transfer data to Excel. If you are running a server program, this can be a good way to remove batch data processing from the client.
To transmit data without "automation", you can use the following methods:
•
Transfer data to a tab-separated or comma-separated text file. Then, Excel can analyze the text file as a cell on the worksheet.
•
Use ADO. NET to transfer data to a worksheet.
•
Transfer XML data to Excel (Version 2002 and Version 2003 only) to provide data that can be formatted and arranged as rows and columns.
Method
Use "automation" to transmit data one by one
With "automation", you can transmit data to the worksheet one by one in cells: // Start a new workbook in Excel.
M_objExcel = new Excel. Application ();
M_objBooks = (Excel. Workbooks) m_objExcel.Workbooks;
M_objBook = (Excel. _ Workbook) (m_objBooks.Add (m_objOpt ));
// Add data to cells in the first worksheet in the new workbook.
M_objSheets = (Excel. Sheets) m_objBook.Worksheets;
M_objSheet = (Excel. _ Worksheet) (m_objSheets.get_Item (1 ));
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.