Voici comment colorer une ligne sur trois d'une ligne Excel en utilisant OleExcel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <utilcls.h> // ne pas oublier // #include <ComObj.hpp> // a ajouter dans certains cas //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; Variant vMSExcel, vXLWorkbooks, vXLWorkbook, 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"); // colorer une ligne sur trois en jaune clair vWorksheet.OlePropertyGet("Cells").OleProcedure("Select"); vMSExcel.OlePropertyGet("Selection").OlePropertyGet("FormatConditions").OleProcedure("Delete"); vMSExcel.OlePropertyGet("Selection").OlePropertyGet("FormatConditions").OleFunction("Add", 2, 2, "=MOD(LIGNE();3) = 0"); vMSExcel.OlePropertyGet("Selection").OlePropertyGet("FormatConditions", 1).OlePropertyGet("Interior").OlePropertySet("ColorIndex", 36); // jaune clair vWorksheet.OlePropertyGet("Range", "A1").OleProcedure("Select"); }
Partager