有没有人做过标签方面的打印,除了delphi自带的quickreport,还有没有其他的方法。
或者 是自己写的也可以

解决方案 »

  1.   

    给你一个:
    unit Ufm26;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls,printers;type
      TForm26 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Button1: TButton;
        Button2: TButton;
        procedure Button2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form26: TForm26;
      procedure prnstr(str:String;j:integer);
    implementationuses Ufm13;{$R *.DFM}procedure TForm26.Button2Click(Sender: TObject);
    begin
         close;
    end;procedure TForm26.Button1Click(Sender: TObject);
    var
       str:string;
       fdname:array[1..12] of ShortString;
       i:integer;
       strspace:pchar;
    begin
       //try
       Assignprn(prnfile);
       Rewrite(prnfile);
       for i:=0 to 2 do writeln(prnfile); //空打三行
       strspace:=' ';       //将标题前赋空格
       for i:=0 to 100 do write(prnfile,strpas(strspace));
       form13.Label1.Font.Size :=20;
       Printer.Canvas.Font :=form13.Label1.Font;// Memo1.Font;将lable1字体的大小赋给画布
       str:=form13.Label1.Caption;
       writeln(prnfile,str);
       writeln(prnfile);
       for i:=0 to form13.table1.FieldCount-4 do begin
       form13.DBGrid1.Columns.Items[i].Title.Font.Size:=14;
       Printer.Canvas.Font :=form13.DBGrid1.Columns.Items[i].Title.Font;// Memo1.Font;
       end;
       write(prnfile,'| ');
       for i:=0 to form13.table1.FieldCount-4 do
         begin
         write(prnfile,form13.table1.fields[i].fieldname);
         if i=0 then write(prnfile,' | ')
         else if i=1 then write(prnfile,' |')
         else write(prnfile,'|');
         end;
       writeln(prnfile);
       form13.DBGrid1.Font.Size:=14;
       Printer.Canvas.Font :=form13.DBGrid1.Font;
       with form13.table1 Do
       begin
       first;
        while Not EOF Do
         begin
          fdname[1]:=FieldByName('日期').AsString;
          fdname[2]:=FieldByName('时间').AsString;
          fdname[3]:=FieldByName('媒水温度').AsString;
          fdname[4]:=FieldByName('出水温度').AsString;
          fdname[5]:=FieldByName('回水温度').AsString;
          fdname[6]:=FieldByName('燃烧机').AsString;
          fdname[7]:=FieldByName('循环泵').AsString;
          fdname[8]:=FieldByName('补水阀').AsString;
          fdname[9]:=FieldByName('排烟温度').AsString;
        // fdname[10]:=FieldByName('卫热温度').AsString;
        //  fdname[11]:=FieldByName('卫热循环泵').AsString;
        //  fdname[12]:=FieldByName('给水泵').AsString;
        // Writeln(prnfile,fdname[1],fdname[2],fdname[3],fdname[4],fdname[5],fdname[6],fdname[7],fdname[8],fdname[9]);
          for i:=1 to 9 do prnstr(trim(fdname[i]),i);
          writeln(prnfile);
          next;
        end;
       end;
       System.CloseFile(prnfile);
      // except
      // On eprinter Do
      //   MessageDlg('没接打印机或打印机没有开,请连好打印机后再试', mtError,[mbOk], 0);
    end;
      

  2.   

    procedure prnstr(str:String;j:integer);
    var
      //prnfile:Textfile;
      i,n,n0,m,num:integer;
      space:string;//pchar;
    begin
       space:='/';
       num:=length(str);
       n0:=(8-num) div 2;
       n:=2*n0+1;
       if (j>5) and (j<9)then n:=n-2;
       for i:=1 to n do write(prnfile,space);//strpas(space));
       write(prnfile,str);
       m:=8-num-n0;
       m:=2*m+1;
       if num<3 then m:=m-1;
       for i:=1 to m do write(prnfile,space);//strpas(space));
    end;
    end.