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
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <utilcls.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ColorBtn"
#pragma resource "*.dfm"
TForm1 *Form1;
// les Variants doiven etre declares dans le .h
// ils ne sont place la que par comodite pour le test
Variant vMSExcel;
Variant vXLWorkbook, vXLWorkbooks;
Variant vFileName;
Variant vSaveChanges;
Variant vValue, vRange, vCell;
Variant vWorksheet;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
vMSExcel = Variant::CreateObject("Excel.Application");
vMSExcel.OlePropertySet("Visible", true);
vXLWorkbooks = vMSExcel.OlePropertyGet("Workbooks");
vXLWorkbook = vXLWorkbooks.OleFunction("Add");
vWorksheet = vXLWorkbook.OlePropertyGet("Worksheets", 1);
// on selectionne la Feuil1
vWorksheet.OleProcedure("Select");
// premier code
Variant vCell1, vCell2, vCell3;
vCell1 = "A1";
vCell2 = "D10";
vWorksheet.OlePropertyGet("Range", vCell1, vCell2).OleFunction("Select");
vMSExcel.OlePropertyGet("Selection").OleFunction("Copy");
vWorksheet.OlePropertyGet("Range", "H13").OleFunction("Select");
vMSExcel.OlePropertyGet("ActiveSheet").OleProcedure("Paste");
vMSExcel.OlePropertySet("CutCopyMode", false);
vWorksheet.OlePropertyGet("Range", "A1").OleFunction("Select");
// ou si on a besoin des coordonnees X,Y au lieu de A1:D10
// deuxieme code
vWorksheet.OlePropertyGet("Range", vWorksheet.OlePropertyGet("Cells", 1, 1), vWorksheet.OlePropertyGet("Cells", 10, 4)).OleFunction("Select");
vMSExcel.OlePropertyGet("Selection").OleFunction("Copy");
vWorksheet.OlePropertyGet("Cells", 13, 8).OleFunction("Select");
vMSExcel.OlePropertyGet("ActiveSheet").OleProcedure("Paste");
vMSExcel.OlePropertySet("CutCopyMode", false);
vWorksheet.OlePropertyGet("Cells", 1, 1).OleFunction("Select");
} |
Partager