1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//n'oublie pas ce using
using System.Reflection;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Declaration des objets à acceder
Object objApp_Late; //Application
Object objBooks_Late; //collection WorkBooks
Object objBook_Late; //classe WorkBook
Object objProp_Late; //propriete Visible de l'objet Application
// Tableau de parametres des valeurs à passer aux prop ou methodes p
//un objet accede
Object[] mesParametres;
// Use server localhost.
string theServer = "localhost";
// Use ProgID
string myStringProdId = "Excel.Application";
// Make a call to the method to get the type information for the given ProgID.
// Obtient le type suivant ProgId
System.Type typeCom = System.Type.GetTypeFromProgID(myStringProdId, theServer, true);
// le Create Object
objApp_Late = System.Activator.CreateInstance( typeCom );
//Accede à une propriete -ici Visible - de l'Objet Application.
mesParametres = new Object[1];
mesParametres[0] = "True";
objProp_Late = objApp_Late.GetType().InvokeMember("Visible",
BindingFlags.SetProperty, null, objApp_Late, mesParametres);
//Get the workbooks collection.
//Accede à une propriete -ici collection Workbooks-
objBooks_Late = objApp_Late.GetType().InvokeMember("Workbooks",
BindingFlags.GetProperty, null, objApp_Late, null);
//Add a new workbook.
//et appelle la methode Add de l'objet collection
objBook_Late = objBooks_Late.GetType().InvokeMember("Add",
BindingFlags.InvokeMethod, null, objBooks_Late, null);
}
private void button2_Click(object sender, EventArgs e)
{
// Declaration de l' objet à acceder
Object RTReg; //ton Application
Object objProriete ; //variable pour proriete à acceder
// Tableau de parametres des valeurs à passer aux proprietes
// de l'objet accede
Object[] mesParametres;
// Use server localhost.
string theServer = "localhost";
// Use ProgID
string StringProdId = "RTGenkey.RTReg";
// Make a call to the method to get the type information for the given ProgID.
// Obtient le type suivant ProgId
System.Type typeRTreg = System.Type.GetTypeFromProgID(StringProdId, theServer, true);
// le Create Object -cree une instance Com du type specifie
RTReg = System.Activator.CreateInstance(typeRTreg);
//Mets la propriete -ici ProductKey - de l'Objet RTReg.
mesParametres = new Object[1];
mesParametres[0] = Trim(Prod);
objProriete = RTReg.GetType().InvokeMember("ProductKey",
BindingFlags.SetProperty, null, RTReg, mesParametres);
//idem pour les suivantes
//Mets la propriete -ici UserKey - de l'Objet RTReg.
mesParametres = new Object[1];
mesParametres[0] = Trim(Util);
objProriete = RTReg.GetType().InvokeMember("UserKey",
BindingFlags.SetProperty, null, RTReg, mesParametres);
//idem pour les suivantes
//RTReg.PCKey = Trim(Ident)
//RTReg.DateKey = DateC
//RTReg.GenKind = 1
//NB:SetSetRegParams est -il un objet ? si oui meme traitement
//que RTReg ensuite ecrire simplement cette affectation.
//SetRegParams = RTReg.Regkey
}
}
} |