Hi,
Have to consider that using this method, the Excel sheet is read as a database table. So, the first line may or may not be considered as a 'header' (argument HDR=Yes or HDR=No) and the the data in each column have to be the same type (interger, real, string, date, ...).
For Excel 2007, you have to use the "Microsoft.ACE.OLEDB.12.0" driver instead of "Micosoft.Jet.OLEDB.4.0" (not tested) and the .xlsx file extension.
(vlax-invoke-method adoconnect 'Open
(strcat "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
fil
";Extended Properties=;Excel 8.0;HDR=No"
)
""
""
nil
)
Thanks gile
I find it
; Connexion sur le fichier Excel
; Retourne la connexion si tout s'est bien passé, sinon nil
;
; 1er argument --> Nom du fichier
;
; Pour ceux qui ont la version antérieur à Office 2007
; il faut que AccessDatabaseEngine.exe (25.3Mo) soit installé pour lire les fichiers xlsx
; http://www.microsoft.com/downloads/fr-fr/confirmation.aspx?familyId=7554f536-8c28-4598-9b72-ef94e038c891&displayLang=fr
(defun Connexion_Xls(fichier / adoconnect data)
(setq adoconnect (vlax-create-object "ADODB.Connection"))
(if (eq (strcase (vl-filename-extension fichier)) ".XLSX")
(setq data (strcat "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
fichier
";Extended Properties='Excel 12.0;HDR=No'"
)
)
(setq data (strcat "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
fichier
";Extended Properties=;Excel 8.0;HDR=No"
)
)
)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke-method (list adoconnect
'Open
data
""
""
nil
)
)
)
nil
adoconnect
)
)
Now, i've an problem.
With an xlsx's file, i write only in cell "A1"
and the the data in each column have to be the same type (interger, real, string, date, ...).
and what you recommended ?
Salut gile
J'ai trouvé la solution pour lire les fichiers xlxs, mais maintenant mon problème et que j'écris que dans la cellule A1.
Par contre, je ne comprends pas ton histoire qu'une colonne doit être d'un même type (réel, entier, etc...)
Si je lis la cellule A1 par exemple et que c'est un string, j'ai un string.
Si je lis la cellule A3 par exemple est que c'est un chiffre, j'ai un réel;
J'évite pour l'instant de lire des plages type A3:C8, car cela ne fonctionne pas correctement, il ne lit que la 1er ligne
ps : Tu as une routine pour trouver toutes les feuilles.
@+