|
[ chkalja @ 03.02.2007. 20:34 ] @
| Kako da u DataReport ubacim podatke iz MSFlexGrid-a.
Treba da odstampam tabelu.
Tabelu sam stampao ovim kodom:
printer.paintpicture grid1.picture,0,0
ali to me zeza ako tabela sadrzi vise stranica.
Nisam do sada radio u DataReportu, pa ne znam da li je
lakse da da stampam preko njega tabelu, ili nekako drugacije.
Hvala |
[ goranvuc @ 03.02.2007. 21:51 ] @
Pa zavisi od toga da li si Grid napunio tako sto si ga vezao za rekordset ili si ga "rucno" napunio (dodavanjem redova i punjenjem celija tekstom). Ako si koristio ono prvo, onda pogledaj malo primere kako se radi sa Data Report-om i mislim da ces lako shvatiti. Ako je ovo drugo, onda ces morati da se vratis na ono prvo - tj. tesko ces moci na taj nacin. Tj. moguce je i posredno, tako sto ces kreirati "memorijski rekordset" i napuniti ga sadrzajem iz Grida, pa njega onda proslediti kao izvor podataka za Data Report.
[ chkalja @ 04.02.2007. 14:17 ] @
Nazalost sam rucno unosio.
OK bi bilo i ovo printer.paintpicture....... ali ako je veca slika od stampaca, slika neprelazi na drugu stranu. Neznam kako to da uradim.
Jel mogu nekako da stavim sliku, pa ako je veca da mi stampa na vise strana
[ goranvuc @ 04.02.2007. 15:14 ] @
Dakle, posto je ovo bilo vec vise puta, seo sam pa sam "nabrzaka" napravio (trebalo mi je oko 10 minuta) primer koristenja Data Reporta koji koristi memorijski rekordset, cije sam kreiranje takodje stavio kao primer i iskomentarisao, a u reportu sam stavio i primer koristenja sekcija, formatiranje podataka u zavisnosti od tipa ...
Napominjem, 10 minuta, sta bi sve moglo da se uradi za par sati ili dana ... ;)
[ chkalja @ 04.02.2007. 17:16 ] @
Hvala nasao sam malo pre neki kod za direktno stampanje tabele (vise stranica)
Code:
Unfortunately the MSFlexGrid control doesn't have built in print functionality. However, the following code demostrates a simple technique for overcoming this limitation:
'Purpose : Sends the contents of the Microsoft's MSFlexgrid control to the default printer.
'Inputs : fgPrint The flexgrid to print
' [lOrientation] The paper orientation (either vbPRORPortrait or vbPRORLandscape)
' [lMaxRowsPerPage] The maximum number of rows to print on a page, if -1 then determines
' this number based on the paper size.
' [lTopBorder] The paper's top border.
' [lLeftBorder] The paper's left border.
' [lRowsToRepeat] The number of rows to repeat at the top of each page (i.e. the number of heading rows).
'Outputs : Returns True if the grid was successfully printed.
'Author : Andrew Baker
'Date : 03/09/2001 13:58
'Notes : The ScaleMode property of object determines the unit of measure used for the paper borders.
'Revisions :
Function FlexGridPrint(fgPrint As MSFlexGrid, Optional lOrientation As Long = vbPRORPortrait, Optional ByVal lMaxRowsPerPage As Long = -1, Optional lTopBorder As Long = 1000, Optional lLeftBorder As Long = 1000, Optional lRowsToRepeat As Long = 0) As Boolean
Dim lRowsPrinted As Long, lRowsPerPage As Long
Dim lThisRow As Long, lNumRows As Long, lImageHeight As Long, lLastImageTop As Long
Dim lPrinterPageHeight As Long, lPagesPrinted As Long, lHeadingHeight As Long
On Error GoTo ErrFailed
fgPrint.TopRow = 1
lNumRows = fgPrint.Rows - 1
lPrinterPageHeight = Printer.Height
lRowsPerPage = lMaxRowsPerPage
lRowsPrinted = lRowsToRepeat
If lRowsToRepeat Then
'Calculate the height of the heading row
For lThisRow = 1 To lRowsToRepeat
lHeadingHeight = lHeadingHeight + fgPrint.RowHeight(lThisRow)
Next
End If
Do
'Calculate the number of rows for this page
lImageHeight = 0
lRowsPerPage = 0
'Setup printer
Printer.Orientation = lOrientation
For lThisRow = lRowsPrinted To lNumRows
lImageHeight = lImageHeight + fgPrint.RowHeight(lThisRow)
If lRowsPerPage > lMaxRowsPerPage And lMaxRowsPerPage <> -1 Then
'Image has required number of rows, subtract height of current row
lImageHeight = lImageHeight - fgPrint.RowHeight(lThisRow)
Exit For
ElseIf lImageHeight + lTopBorder * 2 + lHeadingHeight > lPrinterPageHeight Then 'Allow the same border at the bottom and top
'Image is larger than page, subtract height of current row
lImageHeight = lImageHeight - fgPrint.RowHeight(lThisRow)
Exit For
End If
lRowsPerPage = lRowsPerPage + 1
Next
'Print this page
lPagesPrinted = lPagesPrinted + 1
If lRowsToRepeat Then
'Print heading rows
Printer.PaintPicture fgPrint.Picture, lLeftBorder, lTopBorder, , lHeadingHeight, , 0, , lHeadingHeight
'Print data rows
Printer.PaintPicture fgPrint.Picture, lLeftBorder, lTopBorder + lHeadingHeight, , lImageHeight + lHeadingHeight, , lLastImageTop + lHeadingHeight, , lImageHeight + lHeadingHeight
Else
'Print data rows
Printer.PaintPicture fgPrint.Picture, lLeftBorder, lTopBorder, , lImageHeight, , lLastImageTop, , lImageHeight
End If
Printer.NewPage
'Store printer position
lRowsPrinted = lRowsPrinted + lRowsPerPage
lLastImageTop = lLastImageTop + lImageHeight + lHeadingHeight
Loop While lRowsPrinted < lNumRows
Printer.EndDoc
FlexGridPrint = True
Exit Function
ErrFailed:
'Failed to print grid
FlexGridPrint = False
Debug.Print "Error in FlexGridPrint: " & Err.Description
End Function
'TEST CODE
'Load the grid with demo data
Private Sub Form_Load()
Dim lThisRow As Long
MSFlexGrid1.Rows = 0
MSFlexGrid1.AddItem "Name" & vbTab & "Age"
For lThisRow = 1 To 150
MSFlexGrid1.AddItem "Andrew is ace " & lThisRow & vbTab & 20 + lThisRow
Next
MSFlexGrid1.FixedRows = 1
End Sub
Private Sub MSFlexGrid1_DblClick()
'Print the grid with the top row as a title row
FlexGridPrint Me.MSFlexGrid1, , , , , 1
End Sub
Pogledacu i ovaj kod sto si mi poslao
[ goranvuc @ 04.02.2007. 17:41 ] @
Simpatican primer, ali ja bas nisam ljubitelj "stap i kanap" resenja, svako resenje bez Print Preview funkcionalnosti mi nije bas blisko (da ne spominjemo export mogucnosti ...). U svakom slucaju, tebi ce to valjda "raditi stvar", a mozda si jos nekog ovde obradovao time sto si podelio sa nama ovu simpaticnu proceduru.
[ dava @ 20.03.2007. 08:26 ] @
goranvuc, kako da proslijedimo parametre report-u. Tj. konkretno u tvom 10-to minutnom primjeru da izlista samo one zapise gdje je RB = 1
[ goranvuc @ 20.03.2007. 16:58 ] @
Dovoljno je samo pre poziva procedure stampe "predfiltrirati" podatke po zeljenom kriterijumu; ili metodom Filter od rekordseta, ili otvaranjem drugog rekordseta (ako je rekordset "otvoren" na osnovu SQL upita).
Dakle, nema potrebe u ovom slucaju da parametre prosledjujes reportu, vec saljes podatke koje prethodno pripremis.
[ dava @ 21.03.2007. 14:13 ] @
Ok skontao sam, u rekordset-u filtriram pa onda njega postavim kao datasource.
Hvala
[ Wacdee @ 25.03.2007. 12:49 ] @
Pozdrav svima,
Prvo podatke iz grida upises u privremenu tabelu.
Tabela se zove Col a ima vise kolona koje se redom zovu Col1, Col2 itd.
Funkcija takodje rasporedi sirine kolona kako su u gridu a mozes proslediti i naziv izvestaja.
Za probu ti je potreban i DataReport koji u Detail sekciji ima RptTextBox - ove pod nazivom col1, col2, col3 itd a da bi kolene bile odvojene vertikalnim linijama i RptLine pod nazivom Ld1, Ld2 itd
u Page Header sekciji RptLabel pod nazivom Lbl1, Lbl2, Lbl3 a da bi kolene bile odvojene vertikalnim linijama i RptLine pod nazivom Lz1, Lz2 itd
Public Sub Print_Laser(Grid As MSFlexGrid, naslov As String, Optional Privju As Boolean)
On Error Resume Next
Screen.MousePointer = vbHourglass
'Brisanje priv. tabele za izvestaj
adoCN.Execute "DELETE FROM Col"
Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM Col", adoCN, 2, 3
'Upisivanje podataka iz Grida u tabelu Col
Dim j As Integer
For j = 1 To Grid.Rows - 1
rs.AddNew
If Grid.ColWidth(1) > 20 Then
For i = 1 To Grid.Cols - 1
rs.Fields(i - 1) = Left(Grid.TextMatrix(j, i), 100)
Next i
Else
For i = 2 To Grid.Cols - 1
rs.Fields(i - 2) = Left(Grid.TextMatrix(j, i), 100)
Next i
End If
rs.Update
Next j
rs.Close
rs.Open "SELECT * FROM Col ORDER BY Col_id", adoCN, 3, 1
Dim Sirina As Long 'Sirana izvestaja
Dim Gater As Integer 'Razmak izmedju kolona
Gater = 100
If (Not rs.EOF) Or (Not rs.BOF) Then
With rptA
Set .DataSource = rs
.Caption = naslov
If intPrintOrijent = 2 Then
.Orientation = rptOrientLandscape
Sirina = Printer.Height - .TopMargin - .BottomMargin - Gater
Else
.Orientation = rptOrientPortrait
Sirina = Printer.width - .LeftMargin - .RightMargin - Gater
End If
.Font.Name = insServis.FontPrinter
.Font.Size = insServis.FontPrinterSize
.Font.Charset = insServis.KarakterSet
.Top = 0
.Left = 0
For i = 1 To 16
.Sections("Section2").Controls("Lz" & i).Left = 0
.Sections("Section1").Controls("Ld" & i).Left = 0
Next
Dim sirinaCol As Integer
Dim Sirina_ As Integer
For i = 1 To Grid.Cols - 1
sirinaCol = sirinaCol + Grid.ColWidth(i)
Next
Sirina_ = Sirina * (Grid.width / sirinaCol) 'Ovim podesimo da je ispis uvek u formatu papira bez obzira kako su podesene kolone na gridu
Dim intOd As Integer
If Grid.ColWidth(1) > 20 Then
.Sections("Section2").Controls("Lbl1").Caption = Grid.TextMatrix(0, 1)
.Sections("Section2").Controls("Lbl1").width = Grid.ColWidth(1) * Sirina_ / Grid.width - Gater
.Sections("Section2").Controls("Lbl1").Left = Gater
.Sections("Section2").Controls("Lz1").Left = 0
.Sections("Section1").Controls("Text1").width = Grid.ColWidth(1) * Sirina_ / Grid.width - Gater
.Sections("Section1").Controls("Text1").Left = Gater
.Sections("Section1").Controls("Ld1").Left = 0
If Grid.ColAlignment(1) = 6 Then
.Sections("Section2").Controls("Lbl1").Alignment = 1
.Sections("Section1").Controls("Text1").Alignment = 1
Else
.Sections("Section2").Controls("Lbl1").Alignment = 0
.Sections("Section1").Controls("Text1").Alignment = 0
End If
For i = 2 To Grid.Cols - 1
.Sections("Section2").Controls("Lbl" & i).Caption = Grid.TextMatrix(0, i)
.Sections("Section2").Controls("Lbl" & i).width = Grid.ColWidth(i) * Sirina_ / Grid.width - Gater
.Sections("Section2").Controls("Lbl" & i).Left = Gater + .Sections("Section2").Controls("Lbl" & i - 1).Left + .Sections("Section2").Controls("Lbl" & i - 1).width
.Sections("Section2").Controls("Lz" & i).Left = Gater / 2 + .Sections("Section2").Controls("Lbl" & i - 1).Left + .Sections("Section2").Controls("Lbl" & i - 1).width
.Sections("Section1").Controls("Text" & i).width = Grid.ColWidth(i) * Sirina_ / Grid.width - Gater
.Sections("Section1").Controls("Text" & i).Left = Gater + .Sections("Section1").Controls("Text" & i - 1).Left + .Sections("Section1").Controls("Text" & i - 1).width
.Sections("Section1").Controls("Ld" & i).Left = Gater / 2 + .Sections("Section1").Controls("Text" & i - 1).Left + .Sections("Section1").Controls("Text" & i - 1).width
.Sections("Section1").Controls("Text" & i).Font.Name = insServis.FontPrinter
.Sections("Section1").Controls("Text" & i).Font.Charset = insServis.KarakterSet
If Grid.ColAlignment(i) = 6 Then
.Sections("Section2").Controls("Lbl" & i).Alignment = 1
.Sections("Section1").Controls("Text" & i).Alignment = 1
Else
.Sections("Section2").Controls("Lbl" & i).Alignment = 0
.Sections("Section1").Controls("Text" & i).Alignment = 0
End If
Next
Else 'Nema rednog broja
.Sections("Section2").Controls("Lbl1").Caption = Grid.TextMatrix(0, 2)
.Sections("Section2").Controls("Lbl1").width = Grid.ColWidth(2) * Sirina_ / Grid.width - Gater
.Sections("Section2").Controls("Lbl1").Left = Gater
.Sections("Section2").Controls("Lz1").Left = 0
.Sections("Section1").Controls("Text1").width = Grid.ColWidth(2) * Sirina_ / Grid.width - Gater
.Sections("Section1").Controls("Text1").Left = Gater
.Sections("Section1").Controls("Ld1").Left = 0
If Grid.ColAlignment(2) = 6 Then
.Sections("Section2").Controls("Lbl1").Alignment = 1
.Sections("Section1").Controls("Text1").Alignment = 1
Else
.Sections("Section2").Controls("Lbl1").Alignment = 0
.Sections("Section1").Controls("Text1").Alignment = 0
End If
For i = 3 To Grid.Cols - 1
.Sections("Section2").Controls("Lbl" & i - 1).Caption = Grid.TextMatrix(0, i)
.Sections("Section2").Controls("Lbl" & i - 1).width = Grid.ColWidth(i) * Sirina_ / Grid.width - Gater
.Sections("Section2").Controls("Lbl" & i - 1).Left = Gater + .Sections("Section2").Controls("Lbl" & i - 2).Left + .Sections("Section2").Controls("Lbl" & i - 2).width
.Sections("Section2").Controls("Lz" & i - 1).Left = Gater / 2 + .Sections("Section2").Controls("Lbl" & i - 2).Left + .Sections("Section2").Controls("Lbl" & i - 2).width
.Sections("Section1").Controls("Text" & i - 1).width = Grid.ColWidth(i) * Sirina_ / Grid.width - Gater
.Sections("Section1").Controls("Text" & i - 1).Left = Gater + .Sections("Section1").Controls("Text" & i - 2).Left + .Sections("Section1").Controls("Text" & i - 2).width
.Sections("Section1").Controls("Ld" & i - 1).Left = Gater / 2 + .Sections("Section1").Controls("Text" & i - 2).Left + .Sections("Section1").Controls("Text" & i - 2).width
.Sections("Section1").Controls("Text" & i - 1).Font.Name = insServis.FontPrinter
.Sections("Section1").Controls("Text" & i - 1).Font.Charset = insServis.KarakterSet
If Grid.ColAlignment(i) = 6 Then
.Sections("Section2").Controls("Lbl" & i - 1).Alignment = 1
.Sections("Section1").Controls("Text" & i - 1).Alignment = 1
Else
.Sections("Section2").Controls("Lbl" & i - 1).Alignment = 0
.Sections("Section1").Controls("Text" & i - 1).Alignment = 0
End If
Next
End If
.Sections("Section2").Controls("Lz17").Left = Sirina
.Sections("Section1").Controls("Ld17").Left = Sirina
.Sections("Section2").Controls("Line2").width = Sirina
.Sections("Section2").Controls("Line1").width = Sirina
.Sections("Section2").Controls("Line5").width = Sirina
.Sections("Section1").Controls("Line4").width = Sirina
.Sections("Section4").Controls("lblNaslov").width = Sirina
.Sections("Section4").Controls("lblNaslov").Caption = naslov
.Sections("Section4").Controls("lblFirma").Caption = insFirma.Firma
.Sections("Section4").Controls("lblMesto").Caption = insFirma.Mesto
.Sections("Section4").Controls("lblDatum").Left = Sirina - .Sections("Section4").Controls("lblDatum").width
.Sections("Section3").Controls("lblBrStr").Left = Sirina - .Sections("Section3").Controls("lblBrStr").width
' .Sections("Section4").Controls("lblDatum").Caption = "Datum: " & Date
.Sections("Section4").Controls("lblDatum").Caption = ""
.Sections("Section3").Controls("lblBrStr").Caption = "Str.br.: " & "%p" & " od " & "%P"
.Sections("Section5").Controls("Line3").width = Sirina
.ReportWidth = Sirina
Screen.MousePointer = vbDefault
If Not PrintPrivju Then .Show vbModal
Set .DataSource = Nothing
End With
Else
Screen.MousePointer = vbDefault
MsgBox "Nema podataka za stampu!", vbInformation
End If
rs.Close
Set rs = Nothing
Exit Sub
ErrorHandler:
Screen.MousePointer = vbDefault
End Sub
[ dava @ 26.03.2007. 08:47 ] @
Gorane, kako da labeli posaljem parametar. labela se nalazi u report header-u
[ goranvuc @ 26.03.2007. 09:00 ] @
Nisam te bas razumeo kakav parametar hoces da saljes, ali npr. ako hoces nekoj labeli da promenis naslov (ili bilo sta bilo kojoj kontroli) to radis pre poziva stampe tako sto pristupas odgovarajucoj sekciji po njenom imenu i odgovarajucoj kontroli (takodje po imenu), a evo ti i primer:
Code:
'Primer promene svojstva pre pozivanja stampe
tmpRep.Sections("Section2").Controls("Label4").Caption = "promenio sam naslov"
'Povezivanje podataka
Set tmpRep.DataSource = rstData
'Poziv stampe
tmpRep.Show 1, Me
Primer koji sam ti sada dao se oslanja na projekat koji sam prilozio ranije u ovoj temi.
[ dava @ 26.03.2007. 10:40 ] @
Meni ovo ne radi. Bez ikakve greske report se otvori, ali labela ne dobije string "promenio sam naslov"
U tvom kodu:
Code:
Private Sub Command1_Click()
Dim tmpRep As New rptSample
rptSample.Sections("Section2").Controls("Label5").Caption = "promenio sam naslov"
Set tmpRep.DataSource = rstData
tmpRep.Show 1, Me
Set tmpRep = Nothing
End Sub
[ goranvuc @ 26.03.2007. 11:04 ] @
Ja ne znam sta ti radis, u mom primeru ne postoji "Label5".
[ dava @ 26.03.2007. 11:23 ] @
U tvom primjeru sam ja napravio label5 tako da postoji. Kad ga stavim u bilo koji Section, i u kodu promijenim broj section, nece.
Nemoj misliti da bas toliko ne znam :)
[ goranvuc @ 26.03.2007. 11:29 ] @
Ne mislim ja da ti ne znas, samo ti govorim da je nesto do tvog projekta, tj. nesto si dodao sto nema u mom primeru a utice na tvoj problem. Probaj da dodas ovaj moj kod u moj primer pa ces videti da radi i da je ipak nesto do tebe. Predlazem ti da uploadujes tvoj projekat pa ti onda mogu pomoci, a ne odmah "meni to ne radi". Ja uvek prvo proverim da nije nesto do mene, pa tek onda gledam da li su mozda drugi pogresili.
Pozdrav!
P.S.
Sad sam ponovo pogledao kod koji si ti pogresno kopirao; obrati paznju kojoj instanci reporta podesavas labelu, ti si stavio:
Code:
rptSample.Sections("Section2").Controls("Label5").Caption = "promenio sam naslov"
a ja sam lepo stavio:
Code:
tmpRep.Sections("Section2").Controls("Label4").Caption = "promenio sam naslov"
Da li treba da ti objasnjavam sta se tu u stvari desilo, ili si shvatio i sam. Mislio sam da cu dobiti "hvala" a ne da odmah skaces na mene, a u stvari si ti napravio banalnu gresku u koristenju pogresne instance, jednu menjas, a drugu prikazujes i cudis se sto nece, tj. Goran je kriv ;)
[Ovu poruku je menjao goranvuc dana 26.03.2007. u 12:42 GMT+1]
[ dava @ 26.03.2007. 12:18 ] @
Radi, greska je do mene. I nisam skocio na tebe, a ako mislis da jesam, izvini, a hvala u svakom slucaju.
Hvala jos jednom
Pozdrav :)
...i hvala
[ goranvuc @ 26.03.2007. 12:21 ] @
Dovoljno je i jedno hvala ;) Inace, nisi precizirao da li je to ono sto si prvobitno pitao kada si mislio na prosledjivanje parametra, tj. da li smo pogodili?
[ dava @ 27.03.2007. 08:21 ] @
Na to sam mislio, ok.
E sad, naisao sam na ovaj problem:
Code:
kolicina cijena
20 5
4 10
----------------
kol*cij
Da sracunam cijene znam, ali kako da dobijem cijena * kolicina, tj. u ovom slucaju 140
Ja inace koristim Crystsal Reports, ali treba mi ovo saznanje.
[ goranvuc @ 27.03.2007. 08:47 ] @
Ako si mislio na nesto tipa: izracunate vrednosti na samom reportu onda jedino agregatne funkcije na jednom polju, tj. nije moguce staviti kontrolu za sumarnu funkciju koja radi sumu za (kolicina * cena) vec jedino da vec imas to polje u rekordsetu, kao sto sam i stavio u primeru.
Druga opcija je da iskoristis prethodni kod (podesavanje teksta labele pre stampe) i izracunas sumu pre poziva reporta, a onda tako izracunatu sumu upises kao tekst npr. u futer.
Data Report ima samo osnovnu funkcionalnost, ne ocekuj nista preterano napredno od njega.
[ dava @ 27.03.2007. 09:10 ] @
Ok, izracunacu ih prije poziva reporta.
Dim i as Integer
For i = 1 to 50
"Hvala"
next i
:)
[ goranvuc @ 27.03.2007. 09:13 ] @
Ja bih ti ipak preporucio:
Code:
Do While Not rstData.EOF
'Sabiras
rstData.MoveNext
Loop
ili
Code:
SELECT Cena, Kolicina, Cena*Kolicina AS Vrednost FROM Tabela

Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|