Asp.net Excel macro operations

Source: Internet
Author: User
CSHARP operation macro
1/** // <summary>
2 // call the Excel macro to generate a report based on the input report name and corresponding parameters
3 // if the request succeeds, null is returned. Otherwise, a string containing the error cause is returned.
4 /// </Summary>
5 // <Param name = "reportname"> name of the report to be generated </param>
6 /// <Param name = "rptparams"> list of parameters required for generating the Report </param>
7 /// <returns> </returns>
8 public static string createreports (string rptpath, string rptname, string rptnamefix, hashtable rptparams)
9 {
10 excel. Application oxl;
11
12 string sresult = NULL;
13 try
14 {
15 // start a Excel application
16 oxl = new excel. Application ();
17
18 // hide Excel
19 oxl. Visible = false;
20}
21 catch (exception theexception)
22 {
23 return string. Concat ("An error occurred while requesting the Excel service! ", Theexception. Message );
24}
25 try
26 {
27 // open the master Excel File
28 If (systemconfig. officeverstring = "2003 ")
29 {
30 oxl. workbooks. open (rptpath + "\ oilscorereports \ Templates \ oilscorereports. xla ", missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value );
31 // call VBA to generate a report
32 oxl. run ("createreports. createreports ", rptpath, rptname, rptparams [" dwmc "]," ", rptparams [" rptdate "], rptparams [" strcnt "], rptparams [" userid "], "supervisor", "Audit", "tabulation", rptnamefix, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value );
33}
34 // else
35 //{
36 // oxl. workbooks. open (rptpath + "\ oilscorereports \ Templates \ oilscorereports. xla ", missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value );
37 // call VBA to generate a report
38 // oxl. run ("createreports. createreports ", rptpath, rptname, rptparams [" dwmc "]," ", rptparams [" rptdate "], rptparams [" strcnt "], rptparams [" userid "], "supervisor", "Audit", "tabulation", rptnamefix, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value, missing. value );
39 //}
40
41}
42 catch (exception theexception)
43 {
44 // kill the Excel Process
45 sresult = "An error occurred while generating the report :";
46 sresult = string. Concat (sresult, theexception. Message );
47}
48 finally
49 {
50 oxl. Quit ();
51 marshal. releasecomobject (oxl );
52 GC. Collect ();
53}
54 return sresult;
55
56}

====================
The content here is returned to the friend below.
1. Calling Macros in C # is required. This is also very simple, as I mentioned above.
2. Control the selection of buttons in the form in the macro. The macro can be called to achieve the goal.
3. The specific textures are as follows:

Figure 1

Figure 2
4. I don't know if this can meet your requirements.

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.