If you operate Excel under VC

Source: Internet
Author: User
Source: Click to open the link
Data operation 1. Get sheet. Void getsheet (char * psheetname, _ worksheet & excelsheet) {excelsheet. attachdispatch (excelsheets. getitem (_ variant_t (psheetname);} _ worksheet datasheet; getsheet ("data", datasheet); note: the sheet name must exist in the file; otherwise, the program throws an exception. To adapt to different file operations, the sheet name can be dynamically configured through the configuration file. 2. Get rangevoid getrange (_ worksheet excelsheet, range & excelrange)
{Excelrange. attachdispatch (excelsheet. getcells ();} range datarange; getrange (datasheet, datarange); 3. obtain the data of the specified row and column # define LV (x) _ variant_t (long (x) # define SV (x) _ variant_t (X ). ...... Bool getdata (INT row, int col) {range. attachdispatch (datasheet. getcells ());
Range. attachdispatch (range. getitem (LV (ROW), LV (COL). pdispval); colevariant vresult = range. getvalue2 (); If (vresult. Vt = vt_empty)
Return false; return true;} 4. enter void setvalue (INT row, int Col, char * pdata) {datarange. setitem (LV (ROW), LV (COL), SV (pdata ));
} 5. if a table height variable is dtableheight and the width variable is dtablewidth, copy several copies of the table. The code for copying a row between each table is as follows: int ROW = 1 range rgmyrge2, rgmyrge3for (INT I = 0; I <n; I ++) {rgmyrge2.attachdispatch (datarange. getitem (colevariant (long) (ROW), colevariant (long) 1 )). pdispval, true); rgmyrge3.attachdispatch (rgmyrge2.getresize (colevariant (long) dtableheight), colevariant (long) dtablewidth); rgmyrge3.copy (datarange. getitem (LV (lon G) (row + dtableheight), LV (long (1); ROW = row + dtableheight + 1;} chart operations Excel provides powerful chart processing functions, we can easily draw various statistical reports. As shown in, we will process charts with fixed templates. 1.
Obtain the _ worksheet chartsheet; getsheet ("Graph", chartsheet); void getchart (_ worksheet excelsheet, int dchatno, _ chart & excelchart) {chartobjects objcharts; chartobject objchart; colevariant vopt (disp_e_paramnotfound, vt_error); objcharts = excelsheet. chartobjects (vopt); objchart = objcharts. item (colevariant (short) dchatno ));
Excelchart. attachdispatch (objchart. getchart (), true);} _ chart resultchart; getchart (chartsheet, chartno, resultchart );
Note: The chartno variable indicates the chart sort value, which is the number of charts in a sheet. The sort value is automatically generated based on the order in which the chart is created. 2.
To set a curve, you must accurately describe the curve. The curve description is a serialized string that contains four parts separated by commas (,): 1.
The X-week description of the chart. 3.
Shows the region description of the data based on the curve. 4.
Some items in the curve sorting value (curve ID) in a single chart can be set. The system will take the default value. The final serialization format is as follows: = series ("example", data! $ A $4: $ a $34, data! $ C $4: $ C $34,1), you can also omit the specified X coordinate = series ("example", data! $ C $4: $ C $34,1 ). Void setchartseriessource (_ chart excelchart, short series_id, char * pparamline) {series oseries; oseries = excelchart. seriescollection (colevariant (short) series_id); oseries. setformula (pparamline);} Char szparamline [1024]; sprintf (rgnline, "= series (/" % S/", % s! $ % S $ % d: $ % S $ % d, % d) "," data ", pdataname, pcol, row, pcol, dindexrow [I], 1 ); setchartseriessource (excelchart, 1, szparamline); note: the set data should not be worthy. For example, a curve is formed based on the data region A1: a100. If the A30 position has no data (the region is empty but not zero), the program throws an exception.

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.