Requirements:
We need to save the data list on the interface as an Excel Workbook.
Solution:
Automationfactory:Provides access to registered automated servers.
Createobject (string ):Activate a registered Automation server with the specified programming identifier (progid) and return a reference to it.
Effect:
XAMLCode(Basically no need to write, all written in C # code)
<GridX: Name= "Layoutroot"Background= "White">
</Grid>
CS code:
Public Mainpage ()
{
Initializecomponent ();
Loaded + = New Routedeventhandler (mainpage_loaded );
}
Void Mainpage_loaded ( Object Sender, routedeventargs E)
{
// Indicates whether the Silverlight automation function can be usedProgram
If ( ! Automationfactory. isavailable) Return ;
// Create an Excel Project
VaR Excel = Automationfactory. Createobject ( " Excel. Application " );
Excel. Visible = True ;
// Create an Excel worksheet
VaR workbook = Excel. workbooks;
Workbook. Add ();
// Get default Worksheet (first)
VaR Sheet = Excel. activesheet;
VaR I = 1 ;
// Data to be written into an Excel table
VaR data = New Double [] { 1.0 , 5.0 , 9.5 , 2.7 , 3.2 , 0.6 };
// Write data to an Excel worksheet
Foreach (VAR d In Data)
{
// Write Data to row I of the first column
VaR Cell = Sheet. cells [I, 1 ];
Cell. Value = " The " + I + " Line " ;
// Set the column width to 10.
Cell. columnwidth = 10 ;
// Write Data for row I of the second column
Cell = Sheet. cells [I, 2 ];
Cell. Value = D;
I ++ ;
}
}
Success !!!
Author:Memories of lost youth
Source: http://www.cnblogs.com/lukun/
The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent andArticleThe original text connection is displayed at an obvious location on the page. If you have any problems, you can useHttp://www.cnblogs.com/lukun/Thank you very much for contacting me.