Bonjour,
Je cherche � ouvrir un fichier Excel existant sans utiliser les outils .Net.
Le fichier ne veut pas s'ouvrir il retourne l'exception.
Si je fais ceci �a me cr�� bien un fichier Excel et �a me remplit la cellule :
Pourquoi cela ne marche pas ?
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49 #include <iostream> #import "F:\Program Files\Fichiers communs\Microsoft Shared\Office10\MSO.DLL" no_namespace rename("DocumentProperties","DocumentPropertiesXL") #import "F:\Program Files\Fichiers communs\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" no_namespace #import "F:\Program Files\Microsoft Office\Office10\Excel.exe" rename("ExitWindows", "ExitWindowsWD") rename("DialogBox", "ExcelDialogBox") rename("RGB", "ExcelRGB") no_dual_interfaces using namespace std; int main() { // Initialize COM CoInitialize(NULL); try { Excel::_ApplicationPtr excel; HRESULT hr = excel.CreateInstance(L"Excel.Application"); if(FAILED(hr)) { char msg[1024] = {0}; sprintf(msg, "E: There was an error initializing Excel: %d", hr); printf(msg); } excel->PutVisible (true); //ajoute un workbook Excel::_WorkbookPtr workbook = excel->Workbooks->Open("F:\Documents and Settings\Jérôme\Mes documents\Visual Studio 2008\Projects\PROGRAMME_MAC_BU\PROGRAMME_MAC_BU\Debug\PROGBU.xls"); // Create the workbook //prendre le nom de la feuille active Excel::_WorksheetPtr worksheet = excel->ActiveSheet; // Get the active sheet //nommer la feuille //worksheet->PutName ("Nom de la feuille"); // on remplit une cellule //worksheet->Range["A1"]->Value = "Hello"; //worksheet->SaveAs("c:\\test.xls"); //workbook->Close(); // Close the workbook //excel->Quit(); // Quit excel } catch(_com_error &ce) { MessageBox (NULL, "Erreur !!!", "Error", 0x10010); } CoUninitialize(); }
Merci de m'aider.
Partager