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 ......