Silverlight C # program: Creating an Excel Workbook

Source: Internet
Author: User

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.

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.