mohamed222222
Messages postés161Date d'inscriptionmardi 12 juin 2007StatutMembreDernière intervention22 avril 2009
-
5 nov. 2008 à 10:30
cs_fauve
Messages postés661Date d'inscriptionvendredi 2 décembre 2005StatutMembreDernière intervention23 mars 2011
-
5 nov. 2008 à 18:20
Bonjour ;
j'utilise ce code pour imprimer un datagridview, il m'imprime bien ledatagrid view par contre je voudrai rajoute une date, un titre et le mettre en paysage dans ce code. Ou dois je le rajouter ?
merci beaucoup de votre aide !!!!!!
Private
Sub
ControlPrint_PrintPage(
ByVal
sender
As
Object
,
ByVal
e
As
PrintPageEventArgs)
Handles
MyBase
.PrintPage
'We get the old status of the control
Dim
NewSize
As
New
Size(width, height)
Dim
OldDock
As
DockStyle = m_ctrl.Dock
Dim
OldSize
As
New
Size(m_ctrl.Width, m_ctrl.Height)
Dim
parent
As
Control = m_ctrl
Dim
Parents
As
List(
Of
Control) =
New
List(
Of
Control)()
Dim
OldSizes
As
List(
Of
Size) =
New
List(
Of
Size)()
'enumerate the parents
Do
While
parent.Parent
IsNot
Nothing
Parents.Add(parent.Parent)
OldSizes.Add(parent.Parent.Size)
parent = parent.Parent
Loop
'Change the size of the control to fullt display it and get rid of scrollbars
m_ctrl.Dock = DockStyle.None
m_ctrl.Size = NewSize
'Make sure that the size changes otherwise resize the parents
Do
While
m_ctrl.Size = OldSize
For
Each
c
As
Control
In
Parentsc.Size =
New
Size(c.Width + 100, c.Height + 100)
Next
cm_ctrl.Size = NewSize
Loop
'print dimentions will be according to page size and margins
Dim
printwidth
As
Integer
= width
Dim
printheight
As
Integer
= height
'change the width to fit the paper, and change the height to maintain the ratio
For i Asinteger = 0 To ListView.Columns.Count - 1 ' Permet
d'ajouter les nomsdes colonnes de la listview passer en paramètre dans
le fichier XL
.Cells(1, i+1) = ListView.Columns(i).Text
Next
'Boucle ajoutant tout les items contenus dans la ListView dans lefichier excel
For iCol = 0 To ListView.Items.Count - 1
lvItem = ListView.Items(iCol)
.Cells(iCol + 3, 1) = lvItem.SubItems(0).Text
.Cells(iCol + 3, 2) = lvItem.SubItems(1).Text
.Cells(iCol + 3, 3) = lvItem.SubItems(2).Text
.Cells(iCol + 3, 4) = lvItem.SubItems(3).Text
.Cells(iCol
+ 3, 4).HorizontalAlignment = 3 ' Permet de centrer dans lacellule ( 2
: à gauche 3 : centrer 4 : à droite )
' Ligne précédente peut être supprimé si pas de formatage voulu pourles cellules
.Cells(iCol + 3, 5) = lvItem.SubItems(4).Text
.Cells(iCol + 3, 5).HorizontalAlignment = 3
.Cells(iCol + 3, 6) = lvItem.SubItems(5).Text
.Cells(iCol + 3, 6).HorizontalAlignment = 3
.Cells(iCol + 3, 7) = lvItem.SubItems(6).Text
.Cells(iCol + 3, 7).HorizontalAlignment = 3
Next
End With
' 1° Ligne : Titres en Gras
oSheet.Rows(1).Font.Bold = True
' Paramétrer les marges de la feuille
oSheet.PageSetup.LeftMargin= 0.393700787401575 ' Marge de gauche
oSheet.PageSetup.RightMargin = 0.393700787401575 ' Marge de droite
oSheet.PageSetup.TopMargin =0.393700787401575 ' Marge du haut
oSheet.PageSetup.BottomMargin = 0.393700787401575 ' Marge du bas
' Afficher le quadrillage sur la feuille
oSheet.PageSetup.PrintGridlines = True
' Afficher le tableau de manière centrer horizontalement sur la feuille
oSheet.PageSetup.CenterHorizontally = True
' Paramétrer la feuille en mode Paysage oSheet.PageSetup.Orientation 2 ' ( 1 : Portrait )
oXL.ActiveSheet.printout() ' Lancer l'impression
oXL.Quit() ' Ferme le processus