Accueil > Forum > > > > problème automation excel
problème automation excel
jeudi 10 mai 2007 à 12:39:00 |
problème automation excel

gregorian
|
Bonjour à tous, J'ai un petit problème de mise en page excel. Dans un application, je récupère des données dans un curseur qui doit alors ouvrir un fichier excel. Tout ca, ca va Maintenant, on me demande de quadriller automatiquement ce fichier. Et la j'ai un problème sur la sélection. Sur le net, j'ai trouver le code suivant: loSheet.Range['A1','E15'].select
with Selection.borders(xlEdgeLeft)
.LineStyle=xlContinuous
.Weight=xlThin
.ColorIndex=xlAutomatic
endwith Mais si je fais ca, il me sort le message d'erreur suivant: définition de classe EXCEL.APPLICATION.SELECTION introuvable Dans mon code, je rajoute donc loSel = CREATEOBJECT("Excel.Application.Selection") Mais cela ne semble pas être ca car il me renvoie le même erreur. Qqun peut il m'aider ? PS j'ai déjà été voir l'article de Mike Ganon sur atout fox mais il ne donne pas d'exemple sur la selection... ou plutot, il part d'une feuille et pas d'une sélection range de cell. Merci de votre aide. LOCAL loExcel, loBook, loSheet, lnLine loExcel = CREATEOBJECT("Excel.Application") loBook = loExcel.workbooks.add() loSheet = loBook.worksheets(1) lnLine = 2 loSheet.Range['A1','A1'].EntireColumn.ColumnWidth = 15 loSheet.Range['B1','B1'].EntireColumn.ColumnWidth = 10 loSheet.Range['C1','C1'].EntireColumn.ColumnWidth = 40 loSheet.Range['D1','D1'].EntireColumn.ColumnWidth = 30 loSheet.Range['E1','E1'].EntireColumn.ColumnWidth = 10 loSheet.Range['F1','F1'].EntireColumn.ColumnWidth = 10 loSheet.Range['G1','G1'].EntireColumn.ColumnWidth = 10 loSheet.Range['H1','H1'].EntireColumn.ColumnWidth = 20 loSheet.Range['I1','I1'].EntireColumn.ColumnWidth = 20 loSheet.Range['J1','J1'].EntireColumn.ColumnWidth = 20 loSheet.Range['K1','K1'].EntireColumn.ColumnWidth = 20 loSheet.Range['L1','L1'].EntireColumn.ColumnWidth = 20 loSheet.cells(1,1).Value = "Ref" loSheet.cells(1,2).Value = "PCB" loSheet.cells(1,3).Value = iif(snLangue = 1,"Description","Bescherming") loSheet.cells(1,4).Value = iif(snLangue = 1,"Photo","Picture") loSheet.cells(1,5).Value = iif(snLangue = 1,"Prix","Prijs") if snCont = 1 && si on ne demande pas les infos container, on ne crée pas les colonnes loSheet.cells(1,6).Value = iif(snLangue = 1,"prix container HC","Cont. prijs HC") loSheet.cells(1,7).Value = iif(snLangue = 1,"prix container 20P","Cont. prijs 20P") loSheet.cells(1,8).Value = iif(snLangue = 1,"prix container 40P","Cont. prijs 40P") loSheet.cells(1,9).Value = "Qty HC" loSheet.cells(1,10).Value = "Qty 20p" loSheet.cells(1,11).Value = "Qty 40p" loSheet.cells(1,12).Value = "usine" endif select c_result go top do while !EOF() loSheet.cells(lnLine,1).value = c_result.ref loSheet.cells(lnLine,2).value = c_result.pcb loSheet.cells(lnLine,3).value = c_result.nom *if file(gcDataDir + "PICTURES\ART\" + alltrim(c_result.ref)+".JPEG") * loSheet.range['D3','D3'].select * loSheet.pictures.insert(gcDataDir + "PICTURES\ART\" + alltrim(c_result.ref)+".JPG") *endif *loSheet.cells(lnLine,4).value = "photo" loSheet.cells(lnLine,5).value = c_result.prix if snCont = 1 && si on ne demande pas les infos container, on ne rempli pas les colonnes loSheet.cells(lnLine,6).value = iif(snCont = 1,c_result.prix_conthc,"") loSheet.cells(lnLine,7).value = iif(snCont = 1,c_result.prix_cont20,"") loSheet.cells(lnLine,8).value = iif(snCont = 1,c_result.prix_cont40,"") loSheet.cells(lnLine,9).value = iif(snCont = 1,c_result.qty_contHC,"") loSheet.cells(lnLine,10).value = iif(snCont = 1,c_result.qty_cont20,"") loSheet.cells(lnLine,11).value = iif(snCont = 1,c_result.qty_cont40,"") loSheet.cells(lnLine,12).value = c_result.c_usine endif lnLine = lnLine + 1 skip loop enddo loExcel.visible = .T. ** Quadrillage du rapport: ** Récupération de la dernière case en bas à droite utilisée *!* if snCount = 1 *!* lcMonCell = "L"+str(lnLine) *!* messagebox(lcMonCell) *!* else *!* lcMonCell = "E"+str(lnLine) *!* messagebox(lcMonCell) *!* endif loSheet.Range['A1','E15'].select with loSel.borders(xlEdgeLeft) .LineStyle=xlContinuous .Weight=xlThin .ColorIndex=xlAutomatic endwith release loSheet, loBook, loExcel ENDIF
|
|
dimanche 13 mai 2007 à 14:13:46 |
Re : problème automation excel

Mike Gagnon
|
Réponse acceptée !
Je ne suis pas sur si c'est ceci que tu recherche (J'ai enleve le curseur)
#Define xlEdgeLeft 7 #Define xlContinuous 1 #Define xlThin 2 #Define xlAutomatic -4105 #define xlNone 0 #define xlDiagonalDown 5 #define xlEdgeBottom 9 #define xlDiagonalUp 6 #define xlEdgeTop 8 #define xlEdgeRight 10 #define xlInsideHorizontal 12 #define xlInsideVertical 11 #define xlDiagonalDown 5 #define xlDiagonalUp 6 #define xlEdgeBottom 9 #define xlEdgeLeft 7 #define xlEdgeRight 10 #define xlEdgeTop 8 Local loExcel, loBook, loSheet, lnLine snLangue = 1 snCont = 1 loExcel = Createobject("Excel.Application") loBook = loExcel.workbooks.Add() loSheet = loBook.worksheets(1) lnLine = 2
loSheet.Range['A1','A1'].EntireColumn.ColumnWidth = 15 loSheet.Range['B1','B1'].EntireColumn.ColumnWidth = 10 loSheet.Range['C1','C1'].EntireColumn.ColumnWidth = 40 loSheet.Range['D1','D1'].EntireColumn.ColumnWidth = 30 loSheet.Range['E1','E1'].EntireColumn.ColumnWidth = 10 loSheet.Range['F1','F1'].EntireColumn.ColumnWidth = 10 loSheet.Range['G1','G1'].EntireColumn.ColumnWidth = 10 loSheet.Range['H1','H1'].EntireColumn.ColumnWidth = 20 loSheet.Range['I1','I1'].EntireColumn.ColumnWidth = 20 loSheet.Range['J1','J1'].EntireColumn.ColumnWidth = 20 loSheet.Range['K1','K1'].EntireColumn.ColumnWidth = 20 loSheet.Range['L1','L1'].EntireColumn.ColumnWidth = 20
loSheet.cells(1,1).Value = "Ref" loSheet.cells(1,2).Value = "PCB" loSheet.cells(1,3).Value = Iif(snLangue = 1,"Description","Bescherming") loSheet.cells(1,4).Value = Iif(snLangue = 1,"Photo","Picture") loSheet.cells(1,5).Value = Iif(snLangue = 1,"Prix","Prijs")
If snCont = 1 && si on ne demande pas les infos container, on ne crée pas les colonnes loSheet.cells(1,6).Value = Iif(snLangue = 1,"prix container HC","Cont. prijs HC") loSheet.cells(1,7).Value = Iif(snLangue = 1,"prix container 20P","Cont. prijs 20P") loSheet.cells(1,8).Value = Iif(snLangue = 1,"prix container 40P","Cont. prijs 40P") loSheet.cells(1,9).Value = "Qty HC" loSheet.cells(1,10).Value = "Qty 20p" loSheet.cells(1,11).Value = "Qty 40p" loSheet.cells(1,12).Value = "usine" Endif
*!* select c_result *!* go top *!* do while !EOF() *!* loSheet.cells(lnLine,1).value = c_result.ref *!* loSheet.cells(lnLine,2).value = c_result.pcb *!* loSheet.cells(lnLine,3).value = c_result.nom *!* *if file(gcDataDir + "PICTURES\ART\" + alltrim(c_result.ref)+".JPEG") *!* * loSheet.range['D3','D3'].select *!* * loSheet.pictures.insert(gcDataDir + "PICTURES\ART\" + alltrim(c_result.ref)+".JPG") *!* *endif *!* *loSheet.cells(lnLine,4).value = "photo" *!* loSheet.cells(lnLine,5).value = c_result.prix *!* *!* if snCont = 1 && si on ne demande pas les infos container, on ne rempli pas les colonnes *!* loSheet.cells(lnLine,6).value = iif(snCont = 1,c_result.prix_conthc,"") *!* loSheet.cells(lnLine,7).value = iif(snCont = 1,c_result.prix_cont20,"") *!* loSheet.cells(lnLine,8).value = iif(snCont = 1,c_result.prix_cont40,"") *!* loSheet.cells(lnLine,9).value = iif(snCont = 1,c_result.qty_contHC,"") *!* loSheet.cells(lnLine,10).value = iif(snCont = 1,c_result.qty_cont20,"") *!* loSheet.cells(lnLine,11).value = iif(snCont = 1,c_result.qty_cont40,"") *!* loSheet.cells(lnLine,12).value = c_result.c_usine *!* endif *!* lnLine = lnLine + 1 *!* skip *!* loop *!* enddo loExcel.Visible = .T.
** Quadrillage du rapport:
** Récupération de la dernière case en bas à droite utilisée *!* if snCount = 1 *!* lcMonCell = "L"+str(lnLine) *!* messagebox(lcMonCell) *!* else *!* lcMonCell = "E"+str(lnLine) *!* messagebox(lcMonCell) *!* endif
loSheet.Range("A1:D20").Select With loExcel .Selection.BorderS(xlDiagonalDown).LineStyle = xlNone .Selection.BorderS(xlDiagonalUp).LineStyle = xlNone With .Selection.BorderS(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith With .Selection.BorderS(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith With .Selection.BorderS(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith With .Selection.BorderS(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith With .Selection.BorderS(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith With .Selection.BorderS(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic Endwith Endwith
Release loSheet, loBook, loExcel
Mike Gagnon
|
|
lundi 14 mai 2007 à 10:41:30 |
Re : problème automation excel

gregorian
|
Merci beaucoup.
Ca fonctionne à merveille.
Peux tu me dire ou je pourrais trouver une doc sur les fonctions excell pour savoir au moins dans qu'elle direction aller lorsque je dois faire ce genre de chose.
J'ai rechercher sur le net mais sans succès.
Merci
|
|
lundi 14 mai 2007 à 12:10:25 |
Re : problème automation excel

Mike Gagnon
|
A part les #DEFINE, la meilleur facon de faire est lorsque tu veux faire quelque chose avec Excel, enregistre une Macro, fais ce que tu as a faire, ferme ta Macro, edite la macro, et tout le code ci trouve (En VB, mais tres proche de VFP). Tools-Macro-Record a new Macro.
Mike Gagnon
|
|
lundi 14 mai 2007 à 13:18:12 |
Re : problème automation excel

MichelAtoutFox
|
Tu peux aussi utiliser l'explorateur d'objet de VFP, pour récupérer toutes les constantes de VB (celles que Mike redéfinit en constantes de précompilation), et les propriétés et méthodes utilisables en automation sur Excel
|
|
Cette discussion est classée dans : value, losheet, cells, lnline, range
Répondre à ce message
Sujets en rapport avec ce message
textbox numérique [ par jee0404 ]
bonjour, J,ai un problème avec un textbox numérique. C'est pour la rentré de chiffre dans un textbox. Le problème c'est que je met l'inputmask a '99,9
affichage de données et tri [ par zouheir_ali ]
Bonjour à tous,je travaille avec vfp9 et sqlserver.dans une form j'ai des zones et une grille qui sont reliés par le même curseurje crée un curseur av
modification d'une table [ par slimvir ]
bonjour, j'utilise ce code pour modifier une ligne d'une table mais cette ligne ne se modifier mais elle s'ajoute ?? merciSELECT table1replace Codcli
Livres en rapport
|
Derniers Blogs
TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice CRéATION D'UNE BASE DE DONNéE SOUS SQL AZURECRéATION D'UNE BASE DE DONNéE SOUS SQL AZURE par junarnoalg
Sans rentrer dans les détails, je me propose ici de faire un rapide tour de ce que propose SQL Azure.
SQL Azure est avant tout un service d'hébergement de base de données relationnelles construit sur SQL Server. Il permet aux entreprises d...
Cliquez pour lire la suite de l'article par junarnoalg TECHDAYS PARIS 2010 : LES SERVICES D'APPLICATIONS DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LES SERVICES D'APPLICATIONS DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Xavier Moreels et Julien Bakmezdjian Ce sujet est lié au partage des applications comme services dans SharePoint 2010, ceci représente la possibilité de créer sa propre application qui sera utilisable comme ceux en standard : Search...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|