Imprimir conteúdo do dbgrid
Faço a busca na base de dados e o resultado aparece no dbgrid. Gostaria de imprimir todo o conteúdo deste dbgrid ou selecionar apenas um registro para a impressão.
Abraços
Toninho
Ps. Ao invês de imprimir também poderia exportar o(s) registro(s) como planilha, xml ou como texto.
Abraços
Toninho
Ps. Ao invês de imprimir também poderia exportar o(s) registro(s) como planilha, xml ou como texto.
Tchoninho
Curtidas 0
Respostas
Tchoninho
27/06/2006
ah sim, uso [color=red:7ebda10f32]Delphi 7, Firebird 2.0 e Rave[/color:7ebda10f32]
GOSTEI 0
Renato.pavan
27/06/2006
ah sim, uso [color=red:641e59a2bd]Delphi 7, Firebird 2.0 e Rave[/color:641e59a2bd]
O código que vou postar imprime todo conteudo do dataset que esta no grid pelo rave, este código foi passado pelo meu instrutor quando fiz o curso na impacta.
procedure T_frmModelo.DBGridPrintFooter(Sender: TObject); begin with TBaseReport(Sender) do begin GotoXY(0,SectionBottom); NewLine; //Pula Linha PrintJustify( ´Pág.: ´+FormatFloat(´000´,CurrentPage),0,pjRight,0, SectionRight); end; end; procedure T_frmModelo.DBGridPrintHeader(Sender: TObject); var i:Integer; x: Extended; pj: TPrintJustify; begin with Sender as TBaseReport do begin SetPen(clGray,psSolid,5,pmCopy); GotoXY(SectionLeft,SectionTop); MoveTo(SectionLeft,YPos); LineTo(SectionRight, YPos); SetFont(´Arial´, 14); NewLine; PrintCenter(´TITULO DO RELATORIO´ ,(SectionLeft+SectionRight)/2); NewLine; SetFont(´Arial´, 12); PrintCenter(´SUBTITULO´ ,(SectionLeft+SectionRight)/2); SetFont(´Arial´,8); NewLine; PrintJustify( DateToStr(Now),0, pjLeft,SectionLeft,SectionRight ); PrintJustify( TimeToStr(Now),0,pjRight,0, SectionRight); NewLine; MoveTo(SectionLeft,YPos); LineTo(SectionRight, YPos); NewLine; ClearTabs; x := 0.5; // Polegada for i := 0 to DBGrid1.Columns.Count-1 do begin if DBGrid1.Columns[i].Alignment = taLeftJustify then pj := pjLeft else if DBGrid1.Columns[i].Alignment = taRightJustify then pj := pjRight else pj := pjCenter; SetTab(x,pj,DBGrid1.Columns[i].Width/PixelsPerInch,0,0,0); x := x + (DBGrid1.Columns[i].Width+5)/PixelsPerInch; end; SetFont(DBGrid1.TitleFont.Name,DBGrid1.TitleFont.Size); Bold := True; for i := 0 to DBGrid1.Columns.Count-1 do PrintTab( DBGrid1.Columns[i].Title.Caption ); Bold := False; NewLine; MoveTo(SectionLeft,YPos-FontHeight+0.05); LineTo(SectionRight, YPos-FontHeight+0.05); NewLine; end; end; function T_frmModelo.DBGridPrintPage(Sender: TObject; var PageNum: Integer): Boolean; var i:Integer; begin qryGrid.DisableControls; qryGrid.First; with Sender as TBaseReport do begin SetFont(DBGrid1.Font.Name,DBGrid1.Font.Size); while not cm.qryBrowse.Eof do begin if odd(cm.qryBrowse.RecNo) then // verifica se e impar begin SetBrush($E0E0E0,bsSolid,NIL); SetPen(0,psClear,0,pmCopy); Rectangle(SectionLeft,YPos-FontHeight,SectionRight,YPos); end else SetBrush($FFFFFF,bsSolid,NIL); for i := 0 to DBGrid1.Columns.Count-1 do PrintTab( DBGrid1.Columns[i].Field.Text ); NewLine; qryGrid.Next; if YPos >= (SectionBottom-SectionTop) then NewPage; end; Result := False; end; qryGrid.First; qryGrid.EnableControls; end;
Ai em um DataModule ou no form principal vc coloca um TRVSystem e pra chamar o relatório vc faz assim:
procedure T_frmModelo.actRelatorioExecute(Sender: TObject); begin with _dmPrincipal.RvSystem1 do begin SystemPrinter.MarginBottom := 0.5; SystemPrinter.MarginTop := 0.5; SystemPrinter.MarginLeft := 0.5; SystemPrinter.MarginRight := 0.5; OnPrintHeader := DBGridPrintHeader; OnPrintPage := DBGridPrintPage; OnPrintFooter := DBGridPrintFooter; Execute; OnPrintHeader := NIL; OnPrintPage := NIL; OnPrintFooter := NIL; end;
O ideal seria vc colocar isso em um componente, pois com esse codigo vc pode imprimir os dados de qualquer dbgrid.
Espero ter ajudado.
Renato
[]´s
GOSTEI 0
Tchoninho
27/06/2006
Vc criou os procedimentos ou usa um outro componente DBGrid??
O trecho
procedure DBGridPrintHeader(Sender: TObject);
procedure DBGridPrintFooter(Sender: TObject);
O trecho
with TBaseReport(Sender) do
qual componente é esse?? Porque é nele que esta dando erro.GOSTEI 0
Renato.pavan
27/06/2006
O trecho [quote:1bde31b2a7]with TBaseReport(Sender) do
qual componente é esse?? Porque é nele que esta dando erro.[/quote:1bde31b2a7]Colega, desculpe, esqueci de mencionar, inclua no uses dos procedimentos
RpDefine e RpBase
GOSTEI 0