Fórum Imprimir #188220
13/10/2003
0
if print_dialog.PrintToFile then
begin
nome_arquivo := ´C:\Nova pasta\Rel_Sintetico.txt´;
if InputQuery(´Imprimir para arquivo´, ´Forneça o nome do arquivo:´,
nome_arquivo) then
AssignFile(impressora, nome_arquivo)
else
begin
Showmessage(´Forneça o nome e local para gerar o arquivo!´);
exit;
end;
end;
Marcela
Curtir tópico
+ 0Posts
13/10/2003
Beppe
Ataliba
Gostei + 0
13/10/2003
Marcela
Gostei + 0
13/10/2003
Beppe
Gostei + 0
13/10/2003
Marcela
if print_dialog.PrintToFile then
begin
nome_arquivo := ´C:\Nova pasta\Rel_Sintetico.txt´;
if InputQuery(´Imprimir para arquivo´, ´Forneça o nome do arquivo:´,
nome_arquivo) then
AssignFile(impressora, nome_arquivo)
else
begin
exit;
end;
end
else
begin
//Imprime Titulo
Printer.Title := sTitle;
Printer.Orientation := poPortrait;
Printer.BeginDoc;
Printer.Canvas.Pen.Color := 0;
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.TextOut(0, 100, Printer.Title );
// Percorre cada coluna
for F := 0 to sGrid.ColCount - 1 do
begin
// Identifica as coordenadas (X,Y) da coluna de acordo com a largura da
// mesma, conforme o Grid.
X1 := 0;
for TmpI := 0 to (F - 1) do
X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
Y1 := 300;
X2 := 0;
for TmpI := 0 to F do
X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
Y2 := 450;
//monte cabeçalho
case F of
0: cab1 := ´´;
1: cab1 := ´H´;
2: cab1 := ´D´;
3: cab1 := ´H´;
4: cab1 := ´D´;
5: cab1 := ´H´;
6: cab1 := ´D´;
7: cab1 := ´H´;
8: cab1 := ´D´;
9: cab1 := ´H´;
10: cab1 := ´D´;
11: cab1 := ´H´;
12: cab1 := ´D´;
13: cab1 := ´H´;
14: cab1 := ´D´;
15: cab1 := ´H´;
16: cab1 := ´D´;
17: cab1 := ´H´;
18: cab1 := ´D´;
19: cab1 := ´H´;
20: cab1 := ´D´;
21: cab1 := ´H´;
22: cab1 := ´D´;
23: cab1 := ´H´;
24: cab1 := ´D´;
25: cab1 := ´H´;
26: cab1 := ´D´;
end;
// Monta uma área retangular para imprimir com o conteúdo do cabeçalho
Printer.Canvas.Font.Style := [];
TR := Rect(X1, Y1, X2 - 3, Y2);
Printer.Canvas.Font.Size := 7;
Printer.Canvas.Brush.Color := clLtGray;
Printer.Canvas.TextRect(TR, X1 + 5, 350, Cab1);
Printer.Canvas.Brush.Color := clBlack;
Printer.Canvas.FrameRect(TR);
Printer.Canvas.Brush.Color := clWhite;
// Imprime cada linha da coluna.
for TmpI := 1 to sGrid.RowCount - 1 do
begin
// Define as corrdenadas (X,Y) e uma área Retangular
Y1 := 150 * TmpI + 300;
Y2 := 150 * (TmpI + 1) + 300;
TR := Rect(X1, Y1, X2 - 1, Y2);
// Se for a primeira coluna (0) põe fundo cinza, pois é são as Datas de Leitura.
if F = 0 then
Printer.Canvas.Brush.Color := clLtGray
else
Printer.Canvas.Brush.Color := clWhite;
// Imprime o conteúdo da célula (TextRect) e a borda da célula (FrameRect)
Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI-1]);
Printer.Canvas.Brush.Color := clBlack;
Printer.Canvas.FrameRect(TR);
Printer.Canvas.Brush.Color := clWhite;
end;
end;
Printer.EndDoc;
end;
Gostei + 0
13/10/2003
Beppe
Ataliba
Gostei + 0
13/10/2003
Marcela
Gostei + 0
13/10/2003
Beppe
procedure SaveGridToFile(Grid: TStringGrid; const Filename: String); var I, J: Integer; Text: TextFile; Widths: array of Integer; TotalWidth: Integer; begin AssignFile(Text, Filename); Rewrite(Text); try SetLength(Widths, Grid.ColCount); TotalWidth := 0; for I := 0 to Grid.ColCount - 1 do begin Widths[I] := 0; for J := 0 to Grid.RowCount - 1 do begin if Length(Grid.Cells[I, J]) > Widths[I] then Widths[I] := Length(Grid.Cells[I, J]); end; Inc(Widths[I], 2); Inc(TotalWidth, Widths[I]); end; for I := 0 to Grid.RowCount - 1 do begin if I <> 0 then begin for J := 0 to TotalWidth + Length(Widths) + 3 do Write(Text, ´-´); Write(Text, #1310); end; for J := 0 to Grid.ColCount - 1 do begin if J <> 0 then Write(Text, ´ |´); Write(Text, Grid.Cells[J, I]:Widths[J]); end; Write(Text, 1310); end; finally CloseFile(Text); end; end;
t+
Ataliba
Gostei + 0
13/10/2003
Beppe
SaveGridToFile(StringGrid1, ´C:\grid.txt´)
if print_dialog.PrintToFile then begin nome_arquivo := ´C:\Nova pasta\Rel_Sintetico.txt´; if InputQuery(´Imprimir para arquivo´, ´Forneça o nome do arquivo:´, nome_arquivo) then SaveGridToFile(StringGrid1, nome_arquivo) else begin exit; ...
Gostei + 0
13/10/2003
Marcela
Obrigadaaaaaaaa!
Gostei + 0
13/10/2003
Beppe
Abraço,
Ataliba
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)