C # Excel (Chart) Operations)

Source: Internet
Author: User

Develop an Excel chart:

 

Code

  1      # Region  Operate chart  
2 // Create chart object
3   Excel. Chart = M_objexcel.charts.add (type. Missing, ocuurent_sheet, type. Missing, type. Missing) As Excel. Chart;
4 // Chart type
5   Chart. charttype = Excel. xlcharttype. xllinemarkers;
6 // Chart. set_hasaxis ();
7 // Set the data matrix range in the sheet corresponding to the chart.
8 Chartrange = Ocuurent_sheet.get_range (ocuurent_sheet.cells [ 2 , 2 ], Ocuurent_sheet.cells [ 5 ,( 1 + Ds_occurent.tables [ 0 ]. Columns. Count)]);
9 // Bind data
10 // Chart. setsourcedata (chartrange, Excel. xlrowcol. xlrows );
11
12 Chart. haslegend = True ;
13 // Title
14 Chart. hastitle = True ;
15 // Title name
16 Chart. charttitle. Text = " Hub occurrence " ;
17 Chart. Legend. Position = Excel. xllegendposition. xllegendpositionbottom;
18 // Set excely and X axis
19 Excel. Axis categoryaxis = (Excel. axis) m_objexcel.activechart.axes (Excel. xlaxistype. xlcategory, Excel. xlaxisgroup. xlprimary );
20 Categoryaxis. categorytype = Excel. xlcategorytype. xlcategoryscale;
21 Excel. Series se = (Excel. Series) Chart. seriescollection ( 3 );
22 // Chart color settings
23 Se. Border. colorindex = 5 ;
24 Se = (Excel. Series) Chart. seriescollection ( 2 );
25 Se. Border. colorindex = 6 ;
26 Se = (Excel. Series) Chart. seriescollection ( 1 );
27 Se. Border. colorindex = 3 ;
28 // Se. markerbackgroundcolorindex = 5;
29 // Se. markerstyle = excel. xlmarkerstyle. xlmarkerstylestar;
30 Chart. Location (Excel. xlchartlocation. xllocationasobject, ocuurent_sheet.name );
31 // Chart position
32 Ocuurent_sheet.shapes.item ( 1 ). Incrementtop ( - 116 );
33 Ocuurent_sheet.shapes.item ( 1 ). Incrementleft ( - 166 );
34 Float A = 0.84f ;
35 // Chart size
36 Ocuurent_sheet.shapes.item ( 1 ). Scaleheight (A, msotristate. msofalse, msoscalefrom. msoscalefromtopleft );
37 # Endregion

If we use. net COM, then we can record the Excel Gain set (tool -- Gain set -- Recording Gain set). After recording, we open the VBA editor to view the correspondingCode. We can write C # code based on VBA code and use it with slight changes. Here is the VBA operation.

Add a small item:

When we use value2 instead of text II when reading Excel, the read time is sometimes double type. How can we convert it to time type? Datetime. fromoadate

The time for double conversion is as follows:

 

  1   Datetime getdate  =     New  Datetime (  2009  ,  12  ,  30  );
2 Double Number = Getdate. tooadate (); // Convert the datetime to double
3
4 // Double Doublevalue = 0 ;
5 Datetime doubledate = Datetime. fromoadate (number ); // Convert the double to datetime
6
7 Console. writeline (number ); // 0
8
9 Console. writeline (doubledate. tostring ()); // 12/30/2009 12:00:00 AM
10 Console. writeline (doubledate. tostring ( " Yyyymmdd hh: mm: SS " )); // 2009 00:00:00 1230
11

 

Related Article

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.