1 / 19

CLUB DES UTILISATEURS SAS DE QUÉBEC

USAGE DE VBSCRIPT COMME COMPLÉMENT À LA PRODUCTION DE FICHIERS EXCEL Présentation de Jacques Pagé STRiCT Technologies Le 12 novembre 2008. CLUB DES UTILISATEURS SAS DE QUÉBEC. CONTEXTE. Toujours aucun moyen de produire un authentique fichier XLS formaté avec SAS.

odessa
Download Presentation

CLUB DES UTILISATEURS SAS DE QUÉBEC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. USAGE DE VBSCRIPTCOMME COMPLÉMENT ÀLA PRODUCTION DE FICHIERS EXCEL Présentation de Jacques Pagé STRiCT Technologies Le 12 novembre 2008 CLUB DES UTILISATEURS SAS DE QUÉBEC

  2. CONTEXTE • Toujours aucun moyen de produire un authentique fichier XLS formaté avec SAS. • Le tagset ExcelXP, quoique de plus en plus efficace, produit toujours un fichier XML qui impose des contraintes d'utilisation et peut être très long à ouvrir. • Les Procédures PRINT, REPORT et TABULATE connaissent des limites de formatage.Ex. Comment modifier l'apparence d'une celluleselon le contenu d'une autre?

  3. SURVOL DU TAGSET EXCELXP • Expérimental en version 9.1.3 • Disponible à l'adresse:http://support.sas.com/rnd/base/ods/odsmarkup/index.html#download • Dernière version: (1.86) 2008-04-15 • Ouvrir, copier et coller dans l'Éditeur SAS et soumettre; le tagset sera compilé dans SASUSER.TEMPLAT • Produit un fichier XML spécialement adapté pour Excel.

  4. SURVOL DE VBSCRIPT • Langage semblable à Visual Basic, mais non identique. • Interprété naturellement et automatiquement par Windows Scripting Host, disponible dans toutes les versions contemporaines de Windows. • Programme VBScript exécutable à partir d'un programme SAS au moyen des énoncés X ou %SYSEXEC. • Possibilité de générer le programme VBScript au moyen d'une étape DATA afin d'adapter celui-ci au contexte particulier du classeur Excel produit.

  5. EXEMPLE DE BASE (1)‏ Production d'un fichier XML par le Tagset ExcelXP %LET FICH=C:\TEMP\PRDSALE1; ODS TAGSETS.EXCELXP FILE="&FICH..XML" STYLE=SASWEB ; ods tagsets.excelxp options(sheet_name='Pays' Default_Column_Width='24'); PROCTABULATE DATA=SASHELP.PRDSALE MISSING format=nlmny12.; CLASS COUNTRY PRODTYPE; VAR PREDICT ACTUAL; TABLE COUNTRY*PRODTYPE ALL={LABEL="TOTAL" style=[FONT_WEIGHT=BOLD FONT_STYLE=ITALIC]}, SUM=' '*(PREDICT ACTUAL); RUN; ods tagsets.excelxp options(sheet_name='Produits' Default_Column_Width='24'); PROCTABULATE DATA=SASHELP.PRDSALE MISSING format=nlmny12.; CLASS PRODTYPE PRODUCT; VAR PREDICT ACTUAL; TABLE PRODTYPE*PRODUCT ALL={LABEL="TOTAL" style=[FONT_WEIGHT=BOLD FONT_STYLE=ITALIC]}, SUM=' '*(PREDICT ACTUAL); RUN; ODS TAGSETS.EXCELXP CLOSE;

  6. EXEMPLE DE BASE (2)‏ Fichier XML, tel que vu sous Excel

  7. EXEMPLE DE BASE (3)‏ Sauvegarder un fichier XML, tel que produit par le tagset ExcelXP en fichier XLS au moyen de VBScript. Dim Exc, Classeur Set Exc = CreateObject("Excel.Application")‏ Exc.Visible = True Set Classeur = Exc.Workbooks.Open ("C:\STRiCT\Présentations\PRDSALE1.xml")‏ Classeur.Saveas ("C:\STRiCT\Présentations\PRDSALE1.XLS"),1 Exc.Quit

  8. EXEMPLE DE BASE (4)‏ Inclusion dans un programme SAS, suivant la création du fichier XML par TAGSETS.EXCELXP FILENAME VBSCRIPT "C:\TEMP\VBSCRIPT1.VBS"; DATA _NULL_; FILE VBSCRIPT; PUT "Dim Exc, Classeur"; PUT "Set Exc = CreateObject(""Excel.Application"")"; PUT "Exc.Visible = True"; • PUT "Set Classeur = Exc.Workbooks.Open (""&FICH..XML"")"; /* SAUVEGARDER EN FORMAT XLS */ • PUT "Classeur.Saveas (""&FICH..XLS""),1"; PUT "Exc.Quit"; RUN; /* DÉTRUIRE LE FICHIER XLS DU MÊME NOM, S'IL EXISTE DÉJÀ */ %SYSEXEC DEL "&FICH..XLS"; /* EXÉCUTER LE VBSCRIPT POUR CONVERTIR FICHIER XML EN XLS */ option noxwait xsync; %SYSEXEC "C:\TEMP\VBSCRIPT1.VBS";

  9. RETOUR SUR L'EXEMPLE PRÉCÉDENT‏ Pourrait-on voir en caractères gras et en italique la ligne de total en entier?

  10. UTILISATION DES OBJETS ET PROPRIÉTÉS %MACRO VBS; FILENAME VBSCRIPT "C:\TEMP\VBSCRIPT1.VBS"; DATA _NULL_; FILE VBSCRIPT; PUT "Dim Exc, Classeur, Sheet"; PUT "Dim Rangee, Fin"; PUT "Set Exc = CreateObject(""Excel.Application"")"; PUT "Exc.Visible = True"; PUT "Set Classeur = Exc.Workbooks.Open (""&FICH..XML"")"; PUT "For Sheet = 1 To 2"; PUT "Rangee = 1"; PUT "Fin = 0"; PUT 'Do Until Fin = 1'; PUT 'If Classeur.Worksheets(Sheet).Cells(Rangee, 1).Value="TOTAL" Then'; PUT 'Classeur.Worksheets(Sheet).Rows(Rangee).Font.FontStyle="Bold Italic"'; PUT 'Fin = 1'; PUT 'End if'; PUT 'Rangee = Rangee + 1'; PUT 'Loop '; PUT 'Next'; /* SAUVEGARDER EN FORMAT XLS */ PUT "Classeur.Saveas (""&FICH..XLS""),1"; PUT "Exc.Quit"; RUN; %MEND VBS;

  11. APPARENCE D'UNE RANGÉE MODIFIÉE

  12. MODÈLE D'OBJETS EXCEL (1)‏

  13. MODÈLE D'OBJETS EXCEL (2)‏

  14. MODÈLE D'OBJETS EXCEL (3)‏

  15. OBJETS PRINCIPAUX • Application • Workbook • Worksheet • Range

  16. QUELQUES PROPRIÉTÉS DE L'OBJET WORKSHEET

  17. QUELQUES MÉTHODES DE L'OBJET WORKSHEET

  18. RECOMMANDATIONS • Curiosité, patience et détermination • Les exemples fournis dans l'aide d'Excel sont écrits pour VB et non pour VBScript – adaptation requise. • Chercher sur le web pour des exemples concrets et souvent écrits en VBScript.

  19. Présentation disponible sur le site deSTRiCT Technologies: strictt.com/astuces01.html

More Related