Newbigrave
Messages postés3Date d'inscriptionmercredi 24 septembre 2003StatutMembreDernière intervention25 septembre 2003
-
24 sept. 2003 à 23:38
Newbigrave
Messages postés3Date d'inscriptionmercredi 24 septembre 2003StatutMembreDernière intervention25 septembre 2003
-
24 sept. 2003 à 23:40
J'ai recuperé un code permettant d'imprimer un msflexgrid mais qd il y a plus de 2 pages une erreur se lance.
J'ai par ailleur modifier qq petit point et il y en a encore que je ne comprend pas; surtout le MSHflexgrid, je ne connais que le MSflexgrid.
Si celui qui a poster ce code peut m'aiderais je le remercie bocoup!!!
je remet le code :
Sujet:
suivant dans un module, appeler la fonction à partir de vos forms, sans oublier de copier au prélable un mshflexgrid invisible dans votre formprinicipal ( voir code ). Attention pour que l'impression soit correcte, vous devez impérativement déterminer la propriété .colwidth() de chacune des colonnes de votre mshflexgrid à imprimer.
Public Function PrintGrid(pGrid As MSHFlexGrid, sTitre1 As String, stitre2 As String, pHorizontal As Boolean, msg As Integer) As Long
' pGrid = Mshflexgrid à imprimer
' sTitre1 = Titre principal
'stitre2 = sous titre
' pHorizontal = True pour Landscape
On Error GoTo ErrorImpresion
Dim i As Integer
Dim iMaxRow As Integer
Dim j As Integer
Dim msfGrid As MSHFlexGrid
Dim iPaginas As Integer
Dim hauteur As Long
Dim largeur As Long
Dim mylarge As Long
Dim margegauche As Long
Dim margehaute As Long
Dim coul As String
'Printer.ColorMode = vbPRCMMonochrome
pGrid.Visible = False
Printer.PrintQuality = 160
' fMainForm.MSFlexGrid1 est un mshflexgrid invisible
' msflexgrid
' utilisé uniquement pour cette routine
Set msfGrid = fMainForm.MSHFlexGrid1
msfGrid.FixedCols = 0
msfGrid.Clear
If pHorizontal = True Then
Printer.Orientation = vbPRORLandscape
iMaxRow = 42
Else
Printer.Orientation = vbPRORPortrait
iMaxRow = 55
End If
' calcul du nombre de page
If pGrid.Rows Mod iMaxRow = 0 Then
iPaginas = pGrid.Rows \ iMaxRow
Else
iPaginas = pGrid.Rows \ iMaxRow + 1
End If
msfGrid.Rows = iMaxRow
msfGrid.Cols = pGrid.Cols
If msfGrid.Rows > pGrid.Rows Then 'si moins d'une page on met en proportionnel
msfGrid.Rows = pGrid.Rows
If pHorizontal = True Then
hauteur = (9850 / 42) * pGrid.Rows
Else
hauteur = (13450 / 55) * pGrid.Rows
End If
margehaute = 1750 '+ ((13950 - hauteur) / 2)
Else 'si plus d'une page alors
If pHorizontal = True Then
hauteur = 9850
Else
hauteur = 13450
End If
margehaute = 1750
End If
For i = 0 To pGrid.Cols - 1
msfGrid.ColWidth(i) = pGrid.ColWidth(i)
msfGrid.ColAlignment(i) = 2
largeur = largeur + msfGrid.ColWidth(i)
Next
If pHorizontal = True Then
If largeur < 15000 Then
mylarge = largeur
margegauche = ((15000 - mylarge) / 2) + 200
Else
mylarge = 15000
margegauche = 200
End If
Else
If largeur < 11000 Then
mylarge = largeur
margegauche = ((11000 - mylarge) / 2) + 200
Else
mylarge = 11000
margegauche = 200
End If
End If
'Screen.MousePointer = 11 ' hourglass
'impression d'un logo : modifier le nom de l'image
Printer.PaintPicture menu.Image12.Picture, 250, 250, 700, 700
' imprime titre
Printer.Line (200, 200)-(11000, 200) 'ligne du haut
Printer.Line (200, 1000)-(11000, 1000) ' ligne du bas
Printer.Line (200, 200)-(200, 1000)
Printer.Line (11000, 200)-(11000, 1000)
Printer.CurrentY = 500
Printer.FontName = "Time new roman"
Printer.FontBold = True
Printer.FontSize = 14
X1 = Printer.TextWidth(sTitulo)
If X1 > 11000 Then
Printer.FontSize = 12
X1 = Printer.TextWidth(sTitre1)
If X1 > 11000 Then
Printer.FontSize = 10
X1 = Printer.TextWidth(sTitre1)
If X1 > 11000 Then
Printer.FontSize = 8
End If
End If
End If
Printer.CurrentX = 200 + ((11000 - X1) / 2)
Printer.Print sTitre1
' impression de la date
If pHorizontal = True Then
Printer.CurrentX = 8000
Else
Printer.CurrentX = 8000
End If
Printer.CurrentY = 270
Printer.FontSize = 8
Printer.Print Now & " - Page 1 de " & iPaginas
For i = 0 To pGrid.Rows - 2 + iPaginas
If i Mod iMaxRow = 0 And i > 0 Then 'nous sommes en début de nouvelle page
X = i Mod iMaxRow
With msfGrid 'j'imprime la page
.Row = 0
.Col = 0
.ColSel = 0
.RowSel = 0
If pHorizontal Then
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
Else
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
End If
End With
Printer.NewPage
msfGrid.Clear
'il faut recalculer le nombre de lignes qu'il reste à traiter pour calculer la hauteur
'déterminer msfgrid.rows
If pHorizontal = True Then
msfGrid.Rows = pGrid.Rows - ((42 * (i \ iMaxRow)) - 1)
If msfGrid.Rows <= 42 Then 'il n'y aura pas d'autres pages
hauteur = (9850 / 42) * msfGrid.Rows
Else 'il reste pus de 42 lignes donc il y aura une autre page
msfGrid.Rows = 42
hauteur = 9850
End If
Else
msfGrid.Rows = pGrid.Rows - ((55 * (i \ iMaxRow)) - 1)
lplus = i \ iMaxRow + 1
If toto > 2 Then
msfGrid.Rows = msfGrid.Rows + (lplus - 2)
End If
If msfGrid.Rows <= 55 Then 'il n'y aura pas d'autres pages
hauteur = (13450 / 55) * msfGrid.Rows
Else 'il reste pus de 55 lignes donc il y aura une autre page
msfGrid.Rows = 55
hauteur = 13450
End If
End If
For j = 0 To msfGrid.Cols - 1
'reinitialisation des titres
msfGrid.TextMatrix(0, j) = pGrid.TextMatrix(0, j)
Next
'impression du logo
Printer.PaintPicture menu.Image12.Picture, 250, 250, 700, 700
Printer.Line (200, 200)-(11000, 200) 'ligne du haut
Printer.Line (200, 1000)-(11000, 1000) ' ligne du bas
Printer.Line (200, 200)-(200, 1000)
Printer.Line (11000, 200)-(11000, 1000)
Printer.CurrentY = 500
Printer.FontName = "Time new roman"
Printer.FontBold = True
Printer.FontSize = 14
X1 = Printer.TextWidth(sTitre1)
If X1 > 11000 Then
Printer.FontSize = 12
X1 = Printer.TextWidth(sTitre1)
If X1 > 11000 Then
Printer.FontSize = 10
X1 = Printer.TextWidth(sTitre1)
If X1 > 11000 Then
Printer.FontSize = 8
End If
End If
End If
Printer.CurrentX = 200 + ((11000 - X1) / 2)
Printer.Print sTitre1
' Impression de la date et nombre de pages
If pHorizontal = True Then
Printer.CurrentX = 8000
Else
Printer.CurrentX = 8000
End If
Printer.CurrentY = 270
Printer.FontSize = 8
Printer.Print Now & " - Page " & i \ iMaxRow + 1 & " de " & iPaginas
'impression du sous titre
Printer.CurrentX = 200
Printer.CurrentY = 1200
Printer.FontSize = 10
Printer.FontBold = True
Printer.Print stitre2
i = i + 1
End If
For j = 0 To msfGrid.Cols - 1
msfGrid.TextMatrix(i Mod iMaxRow, j) = pGrid.TextMatrix(i - i \ iMaxRow, j)
msfGrid.Row = i Mod iMaxRow
msfGrid.Col = j
pGrid.Row = i - i \ iMaxRow
pGrid.Col = j
'coul = pGrid.CellBackColor
'msfGrid.CellBackColor = coul
Next
Next
With msfGrid
.Row = 0
.Col = 0
.ColSel = 0
.RowSel = 0
If pHorizontal Then
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
Else
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
End If
End With
Printer.EndDoc
pGrid.Visible = True
If msg = 1 Then
MsgBox sTitulo & vbCrLf & iPaginas & " page(s) ont été envoyé à l'imprimante " & Printer.DeviceName, vbInformation, Printer.Port
End If
salir:
Set msfGrid = Nothing
'pubCursorDefault
Exit Function
ErrorImpresion:
Printer.KillDoc
MsgBox "Verifier l'imprimante !!!", vbCritical, "Printer Error"
Resume salir
End Function
Newbigrave
Messages postés3Date d'inscriptionmercredi 24 septembre 2003StatutMembreDernière intervention25 septembre 2003 24 sept. 2003 à 23:40
voici mon code modifier :
Public Function PrintGrid(pGrid As MSFlexGrid, sTitre1 As String, msg As Integer) As Long
On Error GoTo ErrorImpresion
Dim i As Integer
Dim X As Integer
Dim X1 As Integer
Dim lplus As Integer
Dim toto As Integer
Dim iMaxRow As Integer
Dim j As Integer
Dim iPaginas As Integer
Dim hauteur As Long
Dim largeur As Long
Dim mylarge As Long
Dim margegauche As Long
Dim margehaute As Long
Dim msfGrid As MSFlexGrid
If pGrid.Rows Mod iMaxRow = 0 Then
iPaginas = pGrid.Rows \ iMaxRow
Else
iPaginas = pGrid.Rows \ iMaxRow + 1
End If
msfGrid.Rows = iMaxRow
msfGrid.Cols = pGrid.Cols
If msfGrid.Rows > pGrid.Rows Then 'Si moins d'une page on met en proportionnel
msfGrid.Rows = pGrid.Rows
hauteur = (9850 / 40) * pGrid.Rows
Else 'Si plus d'une page alors
hauteur = (9850 / 80) * pGrid.Rows
End If
margehaute = 1750
For i = 0 To pGrid.Cols - 1
msfGrid.ColWidth(i) = pGrid.ColWidth(i)
msfGrid.ColAlignment(i) = 2
largeur = largeur + msfGrid.ColWidth(i)
Next
If largeur < 15200 Then
mylarge = largeur
margegauche = ((15200 - mylarge) / 2) + 200
Else
mylarge = 15200
margegauche = 200
End If
'Imprime le Titre de la page
Printer.Line (200, 200)-(15200, 200) 'ligne du haut
Printer.Line (200, 1000)-(15200, 1000) ' ligne du bas
Printer.Line (200, 200)-(200, 1000)
Printer.Line (15200, 200)-(15200, 1000)
Printer.CurrentY = 500
Printer.FontName = "Time new roman"
Printer.FontBold = True
Printer.FontSize = 14
Printer.CurrentX = 200 + ((12550 - X1) / 2)
Printer.Print sTitre1
'Imprime la date
Printer.CurrentX = 12550
Printer.CurrentY = 270
Printer.FontSize = 8
Printer.Print Now & " - Page 1 de " & iPaginas
For i = 0 To pGrid.Rows - 2 + iPaginas
If i Mod iMaxRow = 0 And i > 0 Then 'Nous sommes en début de nouvelle page
X = i Mod iMaxRow
With msfGrid 'J'imprime la page
.Row = 0
.Col = 0
.ColSel = 0
.RowSel = 0
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
End With
Printer.NewPage
msfGrid.Clear
'Il faut recalculer le nombre de lignes qu'il reste à traiter
'pour calculer la hauteur
'Déterminer msfgrid.rows
If msfGrid.Rows <= 40 Then 'il n'y aura pas d'autres pages
hauteur = (9850 / 40) * msfGrid.Rows
Else 'il reste plus de 40 lignes donc il y aura une autre page
msfGrid.Rows = 40
hauteur = (9850 / 80) * pGrid.Rows
End If
For j = 0 To msfGrid.Cols - 1
'Reinitialisation du Titre
msfGrid.TextMatrix(0, j) = pGrid.TextMatrix(0, j)
Next
Printer.Line (200, 200)-(15200, 200) 'ligne du haut
Printer.Line (200, 1000)-(15200, 1000) ' ligne du bas
Printer.Line (200, 200)-(200, 1000)
Printer.Line (15200, 200)-(15200, 1000)
Printer.CurrentY = 500
Printer.FontName = "Time new roman"
Printer.FontBold = True
Printer.FontSize = 14
Printer.CurrentX = 200 + ((12550 - X1) / 2)
Printer.Print sTitre1
'Impression de la date et du nombre de pages
Printer.CurrentX = 12550
Printer.CurrentY = 270
Printer.FontSize = 8
Printer.Print Now & " - Page " & i \ iMaxRow + 1 & " de " & iPaginas
i = i + 1
End If
For j = 0 To msfGrid.Cols - 1
msfGrid.TextMatrix(i Mod iMaxRow, j) = pGrid.TextMatrix(i - i \ iMaxRow, j)
msfGrid.Row = i Mod iMaxRow
msfGrid.Col = j
pGrid.Row = i - i \ iMaxRow
pGrid.Col = j
Next
Next
With msfGrid
.Row = 0
.Col = 0
.ColSel = 0
.RowSel = 0
Printer.PaintPicture .Picture, margegauche, margehaute, mylarge, hauteur
End With
Printer.EndDoc
If msg = 1 Then
MsgBox sTitre1 & vbCrLf & iPaginas & " page(s) ont été envoyé à l'imprimante " & Printer.DeviceName, vbInformation, "Information"
End If
salir:
Set msfGrid = Nothing
Exit Function
ErrorImpresion:
Printer.KillDoc
MsgBox "Verifier l'imprimante !!!", vbCritical, "Information"
Resume salir