Datagrid imprimer

losc_cartouche Messages postés 51 Date d'inscription mardi 6 février 2007 Statut Membre Dernière intervention 25 mars 2008 - 12 mars 2008 à 20:14
addoul_2006 Messages postés 2 Date d'inscription lundi 13 mars 2006 Statut Membre Dernière intervention 8 juin 2008 - 8 juin 2008 à 20:18
Bonsoir,

Est il possible d'imprimer le contenu d'un Datagrid en Vb6?

Merci

3 réponses

kat40 Messages postés 38 Date d'inscription mardi 3 février 2004 Statut Membre Dernière intervention 19 mars 2008
19 mars 2008 à 19:33
Bonjour,

J'ai essayé d'imprimer un datagrid en VB6, mais ça fonctionnait toujours mal....

Donc, je me suis dis que c'était un table qui alimentait mon datagrid, pourquoi ne pas exporter le contenu de ma table dans un fichier excel et par la suite l'imprimer.

Si tu veux voir toutes mes réflexions:

http://www.developpez.net/forums/showthread.php?t=508451

ma solution :


PrivateSub cmdImprimer_Click()
 
Dim cnx AsNew ADODB.Connection
Dim rs AsNew ADODB.Recordset
 
 
cnx.ConnectionString = "Provider=SQLOLEDB;Data Source=TEST;Initial Catalog=CaisseDCN;User ID=tssss;Password=bonjour;"
cnx.Open
 
rs.Open"SELECT * FROM Depannage", cnx, adOpenStatic, adLockOptimistic ' tablelst-this is yr table name
tmp_val = ""
IfNot rs.EOFThen
rs.MoveLast
rcount = rs.RecordCount
rs.MoveFirst
Close
Open App.Path & "" & tablelst & "Impression.xls"For Output As #1
For i = 0To rs.Fields.Count - 1
If i < rs.Fields.Count - 1Then
tmp_val = tmp_val &amp; rs.Fields(i).Name &amp; vbTab
ElseIf i = rs.Fields.Count - 1Then
tmp_val = tmp_val &amp; rs.Fields(i).Name
EndIf
Next i
tmp_val = tmp_val &amp; vbCrLf
WhileNot rs.EOF
For i = 0To rs.Fields.Count - 1
tmp_val = tmp_val &amp; rs.Fields(rs.Fields(i).Name) &amp; vbTab
Next i
tmp_val = Mid(tmp_val, 1, Len(tmp_val) - 1)
tmp_val = tmp_val &amp; vbCrLf
rs.MoveNext
DoEvents
Label1.Caption = rs.AbsolutePosition &amp; "/" &amp; rcount
Wend
Print #1, tmp_val
EndIf
MsgBox "Processus terminé"
EndSub


Kat40
0
addoul_2006 Messages postés 2 Date d'inscription lundi 13 mars 2006 Statut Membre Dernière intervention 8 juin 2008
8 juin 2008 à 20:16
AddoulTim
Vraiment c'est le travail le plus idéal que j'ai vue. tu doit etre recomponsé.

Merci bien.
0
addoul_2006 Messages postés 2 Date d'inscription lundi 13 mars 2006 Statut Membre Dernière intervention 8 juin 2008
8 juin 2008 à 20:18
AddoulTim
Voila le code sur ado

Private Sub Command1_Click()
tmp_val = ""





If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
rcount = Adodc1.Recordset.RecordCount
Adodc1.Recordset.MoveFirst
Close
Open App.Path & "" & tablelst & "Impression.xls" For Output As #1
For i = 0 To Adodc1.Recordset.Fields.Count - 1
If i < Adodc1.Recordset.Fields.Count - 1 Then
tmp_val = tmp_val & Adodc1.Recordset.Fields(i).Name & vbTab
ElseIf i = Adodc1.Recordset.Fields.Count - 1 Then
tmp_val = tmp_val & Adodc1.Recordset.Fields(i).Name
End If
Next i
tmp_val = tmp_val & vbCrLf
While Not Adodc1.Recordset.EOF
For i = 0 To Adodc1.Recordset.Fields.Count - 1
tmp_val = tmp_val & Adodc1.Recordset.Fields(Adodc1.Recordset.Fields(i).Name) & vbTab
Next i
tmp_val = Mid(tmp_val, 1, Len(tmp_val) - 1)
tmp_val = tmp_val & vbCrLf
Adodc1.Recordset.MoveNext
DoEvents
Label1.Caption = Adodc1.Recordset.AbsolutePosition & "/" & rcount
Wend
Print #1, "Etat des Impayées TUNET"
Print #1,
Print #1,





Print #1, tmp_val
End If
MsgBox "Processus terminé un Fichier XLS a été crée"







End Sub


Private Sub Form_Load()
  text1.Text = Format(Date, "dd/mm/yyyy")
 
End Sub
0
Rejoignez-nous