Slm arkadaslar,
bildiginiz gibi datagrid icindeki veriyi yaziciya gondermek bayaa sorun oluyor...
Yazi cok yukarıda,cok solda olabiliyor.. Veya datagrid icindeki sutun sayisi degistigi zaman yazdirmada problemler olabiliyor.. Asagidaki kod once "toplam yazdirilacak metnin uzunlugunu" buluyor. Sonra da Grid icindeki sutun sayisina ve toplam metin uzunluguna gore yazilar arasindaki bosluklari hesapliyor... Sonucta Gayet guzel bi Print oluyor :)
KOD:
'-----------------------------------------------------
Bir CommandButton'un Click olayina;
Call GRIDPrinTT(DataGrid1)
'-----------------------------------------------------
'--------------- FONKSIYON-----------------------
'-----------------------------------------------------
'Bir Modul icine;
Public Sub GRIDPrinTT(GriD As DataGrid)
Dim NCols As Integer, NRows As Integer, I As Integer, J As Integer
Dim K As Integer, Tabs(50) As Integer, Maxs(50) As Integer
Dim TotalMaxs As Integer, Spaces As Integer, EachSpace As Integer
Dim TempMax As Integer, Title As String
Dim A4W,PBlank
'--- Hesaplama kismi ---
A4W=9900
PBlank=1000
NRows = GriD.ApproxCount
NCols = GriD.Columns.Count
Spaces = NCols - 1
For I = 0 To NCols - 1
GriD.Col = I
For J = 0 To NRows - 1
GriD.Row = J
TempMax = Printer.TextWidth(Trim(GriD.Text))
If TempMax > Maxs(I) Then
Maxs(I) = TempMax
End If
Next J
Next I
For I = 0 To NCols - 1
TotalMaxs = TotalMaxs + Maxs(I)
Next I
EachSpace = (A4W - TotalMaxs + 1) / Spaces
For I = 0 To NCols - 1
If I = 0 Then
Tabs(I) = 1000 + Maxs(I) + EachSpace
Else
Tabs(I) = Tabs(I - 1) + Maxs(I) + EachSpace
End If
If I = NCols - 1 Then
Exit For
End If
Next I
' -- Yazdirma Kismi ---
Printer.CurrentY = 1000
Printer.PaperSize = vbPRPSA4 'A4 kagit boyutu
Printer.FontSize = 14
Title = InputBox("Basligi Yazin:", "Baslik")
Printer.CurrentX = (11907 - (Printer.TextWidth(Title))) / 2
Printer.Print Title
Printer.Line (1000, Printer.CurrentY)-(10900, Printer.CurrentY)
Printer.CurrentY = 1400
Printer.FontName = "Tahoma"
Printer.FontSize = 10
For I = 0 To NRows - 1
If Printer.CurrentY + Printer.TextHeight(GriD.Text) > Printer.ScaleHeight - 1000 Then
Printer.NewPage
End If
GriD.Row = I 'Satir Secme
If I = 0 Then
For K = 0 To NCols - 1
GriD.Col = K
If K = 0 Then
Printer.CurrentX = PBlank
End If
Printer.Print Trim(GriD.Columns(K).Caption);
Printer.CurrentX = Tabs(K)
Next K
Printer.Print
Printer.Line (1000, Printer.CurrentY)-(10900, Printer.CurrentY)
Printer.CurrentY = 1800
End If
For J = 0 To NCols - 1
GriD.Col = J 'Sutun Secme
If J = 0 Then
Printer.CurrentX = PBlank
End If
Printer.Print GriD.Text;
Printer.CurrentX = Tabs(J)
Next
Printer.Print
Next I
Printer.EndDoc
End Sub
|