Excel, as a daily use tool, often uses its import and export capabilities during the development process. After a little exercise, I learned the following import and export function.
Export article:
From the database query to the data to be exported, in the context of XML saved, and finally output the format of Excel, save it.
The first is the header that generates the XML
Create columns
Create rows
Create cells
XmlDocument xd = new XmlDocument ();
String tabletitle = Xmlsheet ();
Xd. LOADXML (Tabletitle);
XmlNodeList NodeList = xd. Documentelement.getelementsbytagname ("Worksheet");//Get XML Worksheet node, there may be multiple.
Import article:
PS: Exported Excel as a template error prone, it is best to create a new Excel as a template, import just test to get a DataTable, the rest of the data needed to filter according to their own needs, the import process may have empty data, later need to pay attention to. If the imported Excel suffix name is. xlsx, it is possible to report that the "microsoft.ace.oledb.12.0" provider is not registered on the local computer. need to download driver, drive connection address http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/ AccessDatabaseEngine.exe.
The process of writing must have a lot of shortcomings, we have many pointers ...
C # Implementing Import and Export of Excel