IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Impression StringGrid "entier"


Sujet :

Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 108
    Par défaut Impression StringGrid "entier"
    Bonjour voila j'arrive bien a imprimer mon stringgrid
    mais la problemme est que quand j'imprime si j'ai beaucoup de ligne dans mon stringgrid l'impression va se limiter a une seule page

    ca fait que je ne vais pas avoir la fin de mon stringgrid d'imprimer.
    comment je pourais faire.

    j'avais penssé a mettre mes données qui ne passe pas dans la première feuille dans un autre stringgrid pour les imprimer a la suite. mais c'est un peut brutal comme solution surtout que j'ai besoins de tout mettre dans un stringgrid (pour la rentrée des notes)

    voila je rapel que je n'imprime pas avec un qickreport.

    merci d'avance ^^

  2. #2
    Membre habitué
    Inscrit en
    Février 2003
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 14
    Par défaut
    avec quel composant u travail pour imprimer le StringGrid

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 108
    Par défaut
    j'utilise + un bout de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    procedure PrintGrid2(sGrid: TStringGrid; sTitle: String);
    var
     X1, X2 : Integer;
     Y1, Y2 : Integer;
     TmpI : Integer;
     F : Integer;
     TR : TRect;
    begin
     Printer.Orientation := poPortrait;
     Printer.Title:=sTitle;
     Printer.BeginDoc;
     Printer.Canvas.Pen.Color:=0;
     Printer.Canvas.Font.Name:='Times New Roman';
     Printer.Canvas.Font.Size:=12;
     Printer.Canvas.Font.Style:=[fsBold, fsUnderline];
     Printer.Canvas.TextOut(0, 0, Printer.Title);
     
     For F:=1 to sGrid.ColCount-1 do begin
       X1:=0;
       if F <> 8  then
       begin
       if F <> 10 then
       begin
     
       For TmpI:=1 to (F-1) do
         X1:=X1+5*(sGrid.ColWidths[TmpI]);
       Y1:=200;            //   Y1:=300;
       X2:=0;
       For TmpI:=1 to F do
         X2:=X2+5*(sGrid.ColWidths[TmpI]);
       Y2:=350;     //  Y2:=450;
       TR:=Rect(X1, Y1, X2-30, Y2);
       Printer.Canvas.Font.Style:=[fsBold];
       Printer.Canvas.Font.Size:=8;
       Printer.Canvas.TextRect(TR, X1+50, 250, sGrid.Cells[F, 0]);    //   250<<350
     
       Printer.Canvas.Font.Style:=[];
       Printer.canvas.Pen.Width := 7;       //épaisseur de la ligne
     
       Printer.Canvas.MoveTo(X1,Y1);          //1
       Printer.Canvas.LineTo(X2,Y1);
     
       Printer.Canvas.MoveTo(X1,Y1);          //2
       Printer.Canvas.LineTo(X1,Y2);
     
       Printer.Canvas.MoveTo(X2,Y2);          //3
       Printer.Canvas.LineTo(X2,Y1);
     
     
       For TmpI:=1 to sGrid.RowCount-1 do begin
         Y1:=140*TmpI + 200;                    //   Y1:=150*TmpI + 300;
         Y2:=140*(TmpI+1)+ 200;                 //    Y2:=150*(TmpI+1)+ 300;
         TR:=Rect(X1, Y1, X2-30, Y2);           //    TR:=Rect(X1, Y1, X2-30, Y2);
         Printer.Canvas.TextRect(TR, X1+50, Y1+25, sGrid.Cells[F, TmpI]);  //X1+50, Y1+50,
     
       Printer.Canvas.MoveTo(X1,Y1);          //1
       Printer.Canvas.LineTo(X2,Y1);
     
       Printer.Canvas.MoveTo(X1,Y1);          //2
       Printer.Canvas.LineTo(X1,Y2);
     
       Printer.Canvas.MoveTo(X2,Y2);          //3
       Printer.Canvas.LineTo(X2,Y1);
     
       Printer.Canvas.MoveTo(X2,Y2);          //4
       Printer.Canvas.LineTo(X1,Y2);
       end;
     end;
    end;
    end;
     Printer.EndDoc;
    end;
    voila ^^

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 108
    Par défaut
    Bon voila j'y arrive mais a la méthode barbare quand même.
    arriver à un nombre N d'information je réécrire mais information dans un nouveau stringgrid.que j'imprime a la suite du 1er.du coup ca me fait 3 stringgrid bien sûr l'utilisateur n'y voit rien mais bon pas trés estétique comme solution.

    bref si qq1 a une solution plus pratique je suis à l'écoute ^^

  5. #5
    Membre Expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 55
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Par défaut
    Il y a peut être un moyen avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    StringGrid1.PaintTo(Printer.Canvas)
    Il faut que je regarde ça un petit peu, donc laisses moi un peu de temps

  6. #6
    Membre Expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 55
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Par défaut
    Voilà,

    Donc je t'ai sorti une procédure qui dessine un StrinGrid Dans un Bitmap.
    Après, il n'y a plus qu'a afficher le Bitmap sur le canvas de l'imprimante.
    Quitte à découper le bitmap en sous bitmap

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    procedure GridToBitMap(Grid:TStringGrid;ABitMap:TBitMap);
    Var AForm:TForm;
        AGrid:TStringGrid;
        i,j,h,w:integer;
    begin
      AForm:=TForm.Create(nil);
      AGrid:=TStringGrid.Create(AForm);
      AGrid.Parent:=AForm;
      AGrid.Ctl3D:=False;
      AGrid.ScrollBars:=ssNone;
      AGrid.color:=Grid.Color;
      AGrid.FixedColor:=Grid.FixedColor;
      AGrid.Font:=grid.Font;
      AGrid.ColCount:=Grid.ColCount;
      AGrid.RowCount:=Grid.RowCount;
      AGrid.FixedCols:=Grid.FixedCols;
      AGrid.FixedRows:=Grid.FixedRows;
      AGrid.Options:=grid.Options;
      AGrid.GridLineWidth:=grid.GridLineWidth;
      AGrid.DefaultDrawing:=grid.DefaultDrawing;
      AGrid.OnDrawCell:=Grid.OnDrawCell;
      i:=0;
      while i<AGrid.ColCount do
      begin
        j:=0;
        while j<AGrid.RowCount do
        begin
          AGrid.Cells[i,j]:=Grid.Cells[i,j];
          inc(j);
        end;
        inc(i);
      end;
      i:=0;
      w:=0;
      while i<AGrid.ColCount do
      begin
         inc(w,AGrid.ColWidths[i]);
         inc(i);
      end;
      i:=0;
      h:=0;
      while i<AGrid.RowCount do
      begin
         inc(h,AGrid.RowHeights[i]);
      inc(i);
      end;
      AGrid.Height:=h+1+AGrid.RowCount*AGrid.GridLineWidth;
      AGrid.Width:=w+1+AGrid.ColCount*AGrid.GridLineWidth;
      ABitMap.width:=AGrid.Width;
      ABitMap.Height:=AGrid.Height;
      AGrid.Refresh;
      AGrid.PaintTo(ABitMap.Canvas,0,0);
      AForm.Free;
    end;
    Et voici comment celà s'utilise

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    procedure TForm1.Button1Click(Sender: TObject);
    var ABitmap:TBitmap;
         Zoom:integer;
    begin
    StringGrid1.Cells[3,3]:='truc';
      ABitmap:=TBitmap.Create;
      try
        //Utilisation de notre fonction
        GridToBitMap(StringGrid1,ABitmap);
     
        //Exemple de Sortie sur l'imprimante
        Zoom:=Printer.
        ARect:=Printer.Canvas.ClipRect;
        Zoom:=(ARect.Bottom-ARect.Top)/ABitmap.Height;
        ARect.Right:=ARect.Left+ABitmap.Width*zoom;
        Printer.BeginDoc;
        Printer.Canvas.StretchDraw(,ABitmap);
        Printer.EndDoc;
      finally
        ABitmap.Free;
      end;
    end;

+ Répondre à la discussion
Cette discussion est résolue.

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo