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
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <utilcls.h>
/*
ceci est inutile
#pragma link "PERFGRAP"
#pragma link "Excel_2K_SRVR"
*/
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Variant vMSExcel, vXLWorkbooks, vXLWorkbook, vWorksheet;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(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");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
vMSExcel.OleFunction("Quit");
vMSExcel = Unassigned;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Variant vFileName;
vFileName = "c:\\test.xls";
vXLWorkbook.OleProcedure("Saveas", vFileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Variant vValue, vRange, vCell;
vRange = "D3";
vCell = vWorksheet.OlePropertyGet("Range", "D3");
vValue = "valeur de la cellule";
vCell.OlePropertySet("Value", vValue);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Variant vSheetName;
vSheetName = "essai2";
vWorksheet = vXLWorkbook.OlePropertyGet("Worksheets", 2);
vWorksheet.OleProcedure("Select");
vXLWorkbook.OlePropertyGet("Worksheets", 2).OlePropertySet("Name", vSheetName);
}
//--------------------------------------------------------------------------- |
Partager