bonjour à tous je suis à la recherche de documentation sur les composants Texcel de builder 6 quelqu'un
pourrait il m'aider à charger un fichier excel avec ce composant ?
Version imprimable
bonjour à tous je suis à la recherche de documentation sur les composants Texcel de builder 6 quelqu'un
pourrait il m'aider à charger un fichier excel avec ce composant ?
tu peux utiliser cette classe :
le fichier .cpp :
le fichier .hCode:
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 //--------------------------------------------------------------------------- #include "Excel.h" //--------------------------------------------------------------------------- TExcel::TExcel(AnsiString nom) { FDejaOpen = true; FOleExcel.Clear(); FWorkbook.Clear(); FWorksheet.Clear(); Connect(); OpenBook(nom); } //--------------------------------------------------------------------------- TExcel::~TExcel() { SaveBook(); CloseBook(); Deconnect(); } //--------------------------------------------------------------------------- void TExcel::Connect(void) { if (FOleExcel.IsEmpty()) { FDejaOpen = true; try { FOleExcel = Variant::GetActiveObject("Excel.Application"); } catch(...) { FOleExcel = Variant::CreateObject("Excel.Application"); FDejaOpen=false; } } } //--------------------------------------------------------------------------- void TExcel::Deconnect(void) { if (!FOleExcel.IsEmpty()) { CloseBook(); if (!FDejaOpen) FOleExcel.OleFunction("Quit"); FOleExcel.Clear(); FWorkbook.Clear(); FWorksheet.Clear(); } } //--------------------------------------------------------------------------- bool TExcel::OpenBook(AnsiString nom) { bool ret=false; Variant name,workbooks; name=nom; name.ChangeType(varOleStr); try { workbooks = FOleExcel.OlePropertyGet("Workbooks"); FWorkbook = workbooks.OleFunction("Open",name); } catch(...) { FWorkbook.Clear(); } if (!FWorkbook.IsEmpty()) ret=true; return(ret); } //--------------------------------------------------------------------------- void TExcel::CloseBook(void) { Variant savechange; savechange=false; if (!FWorkbook.IsEmpty()) { try { FWorkbook.OleFunction("Close",savechange); } catch(...) { } } FWorkbook.Clear(); FWorksheet.Clear(); } //--------------------------------------------------------------------------- void TExcel::SaveBook(void) { if (!FWorkbook.IsEmpty()) { try { FWorkbook.OleProcedure("Save"); } catch(...) { } } } //--------------------------------------------------------------------------- int TExcel::CountSheet(void) { int nb=0; Variant worksheets; if (!FWorkbook.IsEmpty()) { try { worksheets=FWorkbook.OlePropertyGet("Worksheets"); nb = worksheets.OlePropertyGet("Count"); } catch(...) { } } return(nb); } //--------------------------------------------------------------------------- AnsiString TExcel::SelectSheet(int sheet) { AnsiString n=""; if (!FWorkbook.IsEmpty()) { try { FWorksheet = FWorkbook.OlePropertyGet("Worksheets",sheet); FWorksheet.OleProcedure("Activate"); n = FWorksheet.OlePropertyGet("Name"); } catch(...) { } } return(n); } //--------------------------------------------------------------------------- bool TExcel::GetCell(int lig,int col,Variant &value) { bool ret=false; Variant cell; if (!FWorksheet.IsEmpty()) { try { cell=FWorksheet.OlePropertyGet("Cells",lig,col); value=cell.OlePropertyGet("Value"); ret=true; } catch(...) { value.Clear(); } } return(ret); } //--------------------------------------------------------------------------- void TExcel::SetCell(int lig,int col,Variant value) { Variant cell; if (!FWorksheet.IsEmpty()) { try { cell = FWorksheet.OlePropertyGet("Cells",lig,col); value.ChangeType(varOleStr); cell.OlePropertySet("Value",value); } catch(...) { } } } //--------------------------------------------------------------------------- void TExcel::GetMaxRowCol(int &lig,int &col) { Variant cell; if (!FWorksheet.IsEmpty()) { try { cell = FWorksheet.OlePropertyGet("Cells").OleFunction("SpecialCells",11); lig = cell.OlePropertyGet("Row"); col = cell.OlePropertyGet("Column"); } catch(...) { lig=0; col=0; } } } //--------------------------------------------------------------------------- void TExcel::PrintSheet(void) { if (!FWorksheet.IsEmpty()) { try { FWorksheet.OleProcedure("PrintOut"); } catch(...) { } } } //--------------------------------------------------------------------------- void TExcel::SetBorder(int lig,int col,bool visible) { Variant border,cell; if (!FWorksheet.IsEmpty()) { try { cell=FWorksheet.OlePropertyGet("Cells",lig,col); border=cell.OlePropertyGet("Borders"); if (visible) border.OlePropertySet("Weight",-4138); else border.OlePropertySet("Weight",0); } catch(...) { } } } //---------------------------------------------------------------------------
:wink:Code:
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 //--------------------------------------------------------------------------- #ifndef ExcelH #define ExcelH //--------------------------------------------------------------------------- #include <Classes.hpp> //--------------------------------------------------------------------------- class TExcel { private: void Connect(void); void Deconnect(void); bool OpenBook(AnsiString nom); void CloseBook(void); void SaveBook(void); bool FDejaOpen; Variant FOleExcel; Variant FWorkbook; Variant FWorksheet; public: TExcel(AnsiString nom); ~TExcel(); int CountSheet(void); void PrintSheet(void); void SetBorder(int lig,int col,bool visible); AnsiString SelectSheet(int sheet); bool GetCell(int lig,int col,Variant &value); void SetCell(int lig,int col,Variant value); void GetMaxRowCol(int &lig,int &col); }; //--------------------------------------------------------------------------- #endif
merci pour l'info mais j'ai déjà essayer avec ce genre de code
cela fonctionne mais pas pour ce que je veux faire
j'aimerais ouvrir un fichier excel, le modifier etc... et quand je quitte excel j'aimerais avoir de nouveau la main dans mon programme pour pouvoir sauver le fichier excel avec un code particulier
je pensais donc utiliser Texcel, Tworksheet TWorkbook qui ont eux des évènement qui se produisent quand on quitte Excel
mais je n'arrive pas à charger de fichier Excel avec ces composants et je recherche donc des informations à ce sujet car je n'ai pas d'aide d'installer dans c++ builder sur ces composants
voilà mon problème
Citation:
Envoyé par Freeze
je vois pas trop ce qui te manque dans ce genre de code ... quant aux composants fournit avec Borland C++ Builder, je te confirme qu'il n'y a pas de documentation, quant à leur fiabilité, j'en mettrai pas ma main à couper ( j'ai moi même pu vérifier le bordel que ca génère avec différentes versions de Office )... je préfère largement le OLE ...
merci pour l'info
si on utilise Ole, j'arrive à ouvrir un fichier excel à le visualiser dans Excel
mais quand je quitte j'aimerai qu excel ne me demande pas de confirmation pour la sauvegarde du fichier que j'ai modifier
je sauve en fait un fichier au format csv et excel me pose trois ou quatre question pour pouvoir faire sa sauvegarde et c'est très ennnuyeux
j'aimerais qu'il sauve le fichier sans demander de confirmation
mais si je mets displayAlerts à false Excel ne sauve plus rien !!!
je crois comprendre ce que tu veux ... je te conseille de te pencher sur les macros en VBA ... c'est la meilleure méthode à mon avis ... :wink:
faire une macro de sauvegarde en vba qui enlèverait displayAllerts quand je quitte Excel c'est faisable mais c'est trop compliqué d' installer la macro de manière automatique sur les postes où se trouve mon programme et puis comment installer une macro de manière automatique ???
jai résolu le problème en utilisant un olecontainer et en sauvant moi-même le fichier Excel sous le format CSV
seul petit soucis , c'est un peu plus lent pour l'ouverture et la fermeture du fichier Excel
Si quelqu'un a une idée pour accélerer cela, elle sera la bienvenue
merci