StringGrid. Please!!

Delphi

03/11/2003

Eu tenho duas funções onde imprime o conteúdo de um StringGrid. A primeira procedure Imprimi direto para a impressora e a segunda Imprimi para arquivo.
Além de imprimir o conteúdo desta StringGrid eu gostaria tb de imprimir o conteúdo de outras duas StringGrid que fiz de cabecalho da StringGrid anterior.
O problema é: eu não consigo imprimir mais de uma StringGrid e na verdade eu tenho que imprimir três, os dois cabeçalhos mais o conteudo, mas não consigo, tentei de tudo e naõ dá certo...
O código fonte que imprimi um StringGrid está em anexo, se puder me ajudar eu agradeço muito.

procedure PrintGrid(sGrid: TStringGrid; sTitle : string); 
var 
  X, Y, 
  Lin, 
  Col          : Integer; 
  TR           : TRect; 
  cab1         : string; 
begin 
   //Titulo 
   Printer.Orientation := poPortrait; 
   Printer.Title := sTitle; 
   Printer.Orientation := poPortrait; 
   Printer.BeginDoc; 
   Printer.Canvas.Pen.Color  := 0; 
   Printer.Canvas.Font.Name  := ´MS Sans Serif´; 
   Printer.Canvas.Font.Size  := 8; 
   Printer.Canvas.TextOut(0, 100, Printer.Title ); 

   // Percorre cada coluna 
   for Col := 0 to sGrid.ColCount - 1 do 
   begin 
     // Identifica as coordenadas (X,Y) da coluna de acordo com a largura da 
     // mesma, conforme o Grid. 
     X := 0; 
     for Lin := 0 to (Col - 1) do 
        X := X + 5 * (sGrid.ColWidths[Lin]); 

     // Imprime cada linha da coluna. 
     for Lin := 1 to sGrid.RowCount - 1 do 
     begin 
        // Define as corrdenadas (X,Y) e uma área Retangular 
        Y := 150 * Lin + 300; 
        TR := Rect(X, Y, X2 - 1, Y2); 
        // Se for a primeira coluna (0) põe fundo cinza 
        if Col = 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[Col, Lin - 1]); 
        Printer.Canvas.Brush.Color := clBlack; 
        Printer.Canvas.FrameRect(TR); 
        Printer.Canvas.Brush.Color := clWhite; 
     end; 
   end; 
   Printer.EndDoc; 
end; 

//-------------------------------------------------

procedure SaveGridToFile(Grid, Grid2: 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; 




Marcela

Marcela

Curtidas 0
POSTAR