C # Import and Export Excel files,

Source: Internet
Author: User

C # Import and Export Excel files,

As a daily tool, Excel often uses its import and export function during development. After a small exercise, I learned the Import and Export function.

Export:

From the database query to the data to be exported, save it in xml format, and finally output the excel format.

First, generate the xml header.

Create a column

Create row

Create Cells

XmlDocument xd = new XmlDocument ();

String TableTitle = XmlSheet ();

Xd. LoadXml (TableTitle );

XmlNodeList NodeList = xd. DocumentElement. GetElementsByTagName ("Worksheet"); // you can obtain multiple worksheet nodes of xml.

Import:

Ps: the exported excel file is prone to errors when it is used as a template. It is best to create a new excel file as a template. The imported file is only used to test and obtain the datatable, and the remaining data is filtered according to your needs, there may be null data in the import process. Pay attention to it later. If the import excelsuffix is .xlsx, it may be reported that the "Microsoft. ACE. OLEDB.12.0" provider is not registered on the local computer. Driver to be downloaded. Driver connection address: Required.

There must be many shortcomings in the writing process ......

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.