d'excel avant excel 2003.
J'ai travaillé une création de feuille Excel avec COmate. Mon problème est
que je n'arrive pas`mettre les bordures.
Voici les résultats, cela fonctionne Avec Excel 2007 devrait aussi fonctionner avec excel 2003. ne fonctionnera pas avec version antérieur a 2003.
Code : Tout sélectionner
;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch. SRod
;Some code are base from Excel Demo from Srod
;*===========
;
;A very special mention to Srod for the COMate
;
;*Excel demo.
;/////////////////////////////////////////////////////////////////////////////////
;Excel Hierarchy, Organigramme excel  From Flype (PureXLs)
;<Workbook>
;  <Styles>
;    <Style>
;      <Alignment/>
;      <Borders>
;        <Border/>
;      </Borders>
;      <Font/>
;      <Interior/>
;      <NumberFormat/>
;      <Protection/>
;    </Style>
;  </Styles>
;  <Worksheet>
;    <Table>
;      <Column/>
;      <Row>
;        <Cell>
;          <Data/>
;        </Cell>
;      </Row>
;    </Table>
;  </Worksheet>
;</Workbook>
;}
IncludePath "M:\Purebasic\Source"
XIncludeFile "COMate.pbi"
Global StrgHeader.s = "&C Voici Mon Titre"  ; "&C" to center 
date$ = FormatDate("%dd/%mm/%yyyy", Date())
Define.COMateObject oXL, Application
Define.COMateObject oWbk, WorkBook
Define.COMateObject oWkSht, WorkSheet
Define.COMateObject oSht, Sheet
Define.COMateObject oRng, Range
oXL = COMate_CreateObject("Excel.Application")
If oXL
  If oXL\SetProperty("Visible = #True") = #S_OK
    ;------------------------------------------------------------------------------------------------
    ;Setting Application Preference,  Choisir les préférences par défault de l'application
    ;------------------------------------------------------------------------------------------------
    ;
    ; Setting default Font for Application, Modifier la police par défaut de l'application
    oXL\SetProperty ("StandardFont = 'Arial' ")
    ; Setting default Font size for Application,  Modifier la grandeur de la police de l'application
    oXL\SetProperty ("StandardFontSize = 10 ")
    ;Opening a new workbook with only 1 sheet,  ouvrir un nouveau classeur avec 1 seule feuille
    oXL\setproperty("SheetsInNewWorkbook = 1")
    ;------------------------------------------------------------------------------------------------  
    ;------need to restart the application to apply default,  l'application doit être réouverte pour que cela s'applique
    ;
    ;Workbook---------------------------------------------------------------------------
    ;Add a worbook,  ajout d,un classeur
    oWbk= oXL\GetObjectProperty("Workbooks\Add")
    ;------------------------------------------------------------------------------------
    ;
    ;-------------------------------WorkSheet, Feuille-----------------------------------------
    ;set the activeworksheet, initialiser la feuille active
    oWkSht = oWbk\GetObjectProperty("ActiveSheet")
    ;Give the Active Sheet a Name, Donnez un nom à la feuille active
    oWkSht\SetProperty("Name = 'Janvier'")
    ;Setting up Center Header,(same For leftHeader, Right header,  Config en-tête centre, même chose pour en-ête droite et gauche
    oWkSht\setproperty("PageSetup\CenterHeader = '" + StrgHeader + "' AS String ")
    ;Setting up Right Footer,(same For Center footer, Right Footer). &P = page number. Config pied-de-page, même chose pour  droite et gauche
    oWkSht\setproperty("PageSetup\RightFooter = '&P' ")
    ;------------------------------------------------------------------
    ;Setting up margins, Configuration des marge
    oWkSht\setproperty("PageSetup\TopMargin = 36")  ; 36 = 1/2" or 1.27cm
    oWkSht\setproperty("PageSetup\BottomMargin = 36") 
    oWkSht\setproperty("PageSetup\LeftMargin = 36")
    oWkSht\setproperty("PageSetup\RightMargin = 36")
    ;-------------------------------------------------------------------
     ;Setting Column's width, ajuster la largeur de la colonne
    oWkSht\setproperty("Range('A1')\Columnwidth = 20")
    oWkSht\setproperty("Range('E1')\Columnwidth = 15")
    ;----------------------------------------------------------------------------------------
    
    ;--------------------------with Range,---avec une Sélection -----------------------------
    ; setting Range,   configuration d'une sélection de cellules
    oRng = oXL\GetObjectproperty("Range('A1:F1')")
    ;oRng\setproperty("Range('A1:F1')\HorizontalAlignment =xlHAlignCenter");
    ; setting font style to bold on the range,   Configurer le style de police en gras sur la selection de cellule
    oRng\setproperty("Range('A1:F1')\Font\Bold = #True")
    ; Merging a range of cell,  Fusionner une sélection de cellules      
    oRng\setproperty("Range('A5:B5')\MergeCells = #True")
    
    
    ;------------HorizontalAlignment Constants center = -4108, left = -4131, right= -4152, justify = -4130
    ;------------Constante d'alignement Horizontal   centré = -4108, gauche = -4131, droite = -4152, justifié = -4130   
    
    ;Setting HorizontalAlignment for range, , Config  Alignement Horizontal d'une sélection de cellule
    oRng\setproperty("Range('A1:A5')\HorizontalAlignment = -4108") 
    ;Setting Horizontal Alignment for Columns, , Config  Alignement Horizontal sur une colonne
    oWkSht\SetProperty("Columns('B')\HorizontalAlignment = -4131")
    ;Setting Horizontal Alignment for a cell, , Config  Alignement Horizontal sur une cellule                                                      
    oWkSht\SetProperty("Cell(1,1)\HorizontalAlignment = -4152")
    ;-----------------------------------------------------------------------------------
    oWkSht\SetProperty("Borders(xledgeBottom)\linestyle = 1")
    oWkSht\SetProperty("Borders(xledgeBottom)\weight = xlThin")
    oWkSht\SetProperty("Borders(xledgeBottom)\Colorindex = 1")
    oWkSht\SetProperty("XLPageBreak = -4135")
    ;-----------------------------------------------------------------------------------
   
    If oWbk
      ;-changing font font size font color of 1 cell,  changer police, Grandeur de police ou couleur dans une cellule
      ;---------------------------------------------------------------------------------------------------
      ; Font manipulation ,  Manipulation des polices dans une cellule
      ; set Font Name,  Changer police
      oWkSht\SetProperty("Cells(1,1)\Font\name = 'ArialNarrow'")
       ; set Font size,  Dimension
      oWkSht\SetProperty("Cells(1,1)\Font\Size = 12")
      ; set Font Style , Style de police
      oWkSht\SetProperty("Cells(1,1)\Font\FontStyle = 'Italic'")  ;Bold, Italic, Bold Italic as string
      ; set Font underline,  Police Soulignée
      oWkSht\SetProperty("Cells(1,1)\Font\underline = #False")  ;As boolean (#True, false) 
      ;  Text Color index  Index de couleur du texte
      ; 1 = noir 2 = Blanc ?, 3 =Rouge, 4 =vert,  5 = Blue, 6 = Jaune, 7 = Rose, 8 = Turquoise as integer etc.....
      oWkSht\SetProperty("Cells(1,1)\Font\Color =  5") 
      ;Write Text in a sheet cell  écrire du texte dans une cellule de la feuille spécifiée
      oWkSht\SetProperty("Cells(1,1)\interior\Colorindex = 6")
      ;------------------------------------------------------------------------------------------------------------
      ; Writting some text in cells,  écrire du texte dans les cellules
      oWkSht\SetProperty("Cells(1,1) = 'Hello'")
      oWkSht\SetProperty("Cells(1,2) = 'from'")
      oWkSht\SetProperty("Cells(1,3) = 'COMate!'")
      oWkSht\SetProperty("Cells(1,4) = 'is working'") 
      oWkSht\SetProperty("Cells(1,5) = 'Today$0027s date is'")  ;$0027 is a hex escape code used to insert a ' (ascii 39) character.
      oWkSht\SetProperty("Cells(1,6) = '" + date$ + "' AS DATE")
      oWkSht\SetProperty("Cells(4,1) = 6.25")
      oWkSht\SetProperty("Cells(5,1) = 'C$0027est vraiment pas façile'")
      oRng\Release()
      oWkSht\Release()
      oWbk\Release()
      oXL\Invoke("Quit()") 
      
    EndIf
  EndIf
  oXL\Release()
Else
  MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf