Create an Excel file with Office 2003 Schemas

zhaozj2021-02-16  51

EXCEL files in .NET generally need to import COM controls, this article describes the practice of creating Excel files using Office 2003 Schemas.

Microsoft released Office 2003 Schemas, and the chick shot was used to experiment with the method of creating an Excel file through Office 2003 Schemas. The transformation file transform.xsl is defined as follows:

The main test code is as follows:

DataSet DS = New DataSet (); DataTable Table = New DataTable ("TestDataTable"); Table.Columns.Add ("Title", TypeOf (String)); Table.Columns.Add ("Description", TypeOf (String)) Table.Rows.Add (new object [] {"blog", "i love it!"}; Table.Rows.add (new object [] {"9cbs", "China's msdn"}; ds.tables .Add (table); xmlDocument doc = new xmldocument (); doc.loadXML (DS.GETXML ​​()); xpathnavigator nav = doc.documentElement.createnavigator ();

XmlTextWriter writer = new XmlTextWriter ( "output.xls", null); writer.WriteProcessingInstruction ( "xml", "version = /" 1.0 / ""); XslTransform transform = new XslTransform (); transform.Load ( "Transform.xsl "); Transform.Transform (NAV, NULL, WRITER, NULL); Writer.Close ();

This is just the simplest test, can complete the functions of almost any Excel / Word, etc. through Schema; learning ....., 嘻嘻! Finally, this method does not need to install Office 2003.

转载请注明原文地址:https://www.9cbs.com/read-19051.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.050, SQL: 9