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
ENUMERABLECOLLECTIONENUMERABLECOLLECTION par Matthieu MEZIL
Prenons le scénario suivant. On utilise MVVM. On a les deux classes suivantes dans le model : public class Child { } public class Parent { private ObservableCollection < Child > _children; public ObservableCollection < Child > Children { get {...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [HS] CHROME 6 + MOI = COUP DE GUEULE ![HS] CHROME 6 + MOI = COUP DE GUEULE ! par JeremyJeanson
Attention, le poste qui suit n'est pas la complainte d'une personne : Qui n'aime pas Chrome. D'un anti Google. D'un développeur qui a un poil énorme dans la main. Ceux qui me fréquentent savent que je change de navigateur favori tous les 2 ou 3 mois afin ...
Cliquez pour lire la suite de l'article par JeremyJeanson [WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7[WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7 par Audrey
Lors de la réalisation de ma 2ème application Windows Phone 7, j'ai souhaité utiliser un WrapPanel pour afficher plusieurs photos. Mais le contrôle WrapPanel ne fait pas parti de la liste des contrôles inclus dans le SDK de la version Beta des outils pour...
Cliquez pour lire la suite de l'article par Audrey [WP7] BESOIN D'AVOIR DES DONNéES EN CACHE[WP7] BESOIN D'AVOIR DES DONNéES EN CACHE par Nicolas
Les développeurs ASP.NET ont l'habitude de mettre des données en cache pour éviter de requêter a chaque fois la base de données. Et il est toujours utilie de penser que vos utilisateurs mobiles n'ont pas troujours une super connexion 3G/WIFI et un for...
Cliquez pour lire la suite de l'article par Nicolas [TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION[TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION par cyril
Lorsque l'on créé un Work Item dans TFS, il est possible de le classer dans un "area" et dans une "iteration". Dans la plupart des types de projet, un "area" correspond à une catégorie, une "iteration" à un numéro de version. Il est possible de cré...
Cliquez pour lire la suite de l'article par cyril
Logiciels
uTorrent (2.0.4)UTORRENT (2.0.4)C'est un client BitTorrent très puissant et très performant. Comme son nom l'indique, uTorrent (m... Cliquez pour télécharger uTorrent Bureau de Gestion - ERP Devis Facturation (2.02)BUREAU DE GESTION - ERP DEVIS FACTURATION (2.02)- Version gratuite du 10/06/2010
Le Bureau de Gestion est un logiciel dédié à la gestion de l'en... Cliquez pour télécharger Bureau de Gestion - ERP Devis Facturation 4Videosoft Transfert iPod Mac (3.2.08)4VIDEOSOFT TRANSFERT IPOD MAC (3.2.08)4Videosoft Transfert iPod-Mac caractérise principalement à transférer les fichiers iPod vers Mac.... Cliquez pour télécharger 4Videosoft Transfert iPod Mac 4Videosoft HD Convertisseur (3.3.08)4VIDEOSOFT HD CONVERTISSEUR (3.3.08)Etant le meilleur HD Vidéo Convertisseur, 4Videosoft HD Convertisseur, vous pouvez regarder la vi... Cliquez pour télécharger 4Videosoft HD Convertisseur 4Videosoft Transfert iPad Mac (3.2.08)4VIDEOSOFT TRANSFERT IPAD MAC (3.2.08)4Videosoft Transfert iPad-Mac est un logiciel managérial iPad professionnel qui a des fonctions i... Cliquez pour télécharger 4Videosoft Transfert iPad Mac
|