Add chart controls to a worksheet

Source: Internet
Author: User
Add the chart control to the worksheet programmatically

  • 1. process the startup event in sheet1Program, Insert the followingCodeTo add the chart control. Run the following command in the "sheetaskstartup" event in the "sheet1.cs" file:

    Microsoft. Office. Tools. Excel. Chart employeedata;
    Employeedata = This. Controls. addchart (25,110,200,150, "employees ");
    Employeedata. charttype = excel. xlcharttype. xl3dpie;

    // Gets the cells that define the data to be charted.
    Excel. Range chartrange = This. get_range ("A5", "D8 ");
    Employeedata. setsourcedata (chartrange, missing );

  • 2. The following code generates a worksheet host item based on the opened worksheet, and then adds a chart control. Run the task in the thisworkbook_startup event of the thisworkbook. CS file.

  • Private void addchart (){

  • // Use the following line of code in projects that target the. NET Framework 4. worksheet = globals. Factory. getvstoobject (globals. thisaddin. application. activeworkbook. activesheet );

  •  

  • // In projects that target the. NET Framework 3.5, use the following line of code.

  • // Worksheet =

  • // (Excel. worksheet) globals. thisaddin. application. activeworkbook. activesheet). getvstoobject ();

  •  

  • Excel. Range cells = worksheet. Range ["A5", "D8"];

  • Chart chart = worksheet. Controls. addchart (cells, "employees ");

  • Chart. charttype = Microsoft. Office. InterOP. Excel. xlcharttype. xl3dpie;

  • Chart. setsourcedata (cells, missing );

  • }

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.