有个问题和大家探讨,当想打印一个很简单的表格(假设就2个字段,2条记录),除了用第三方控件之外,最简洁的做法应该是什么欢迎大家切磋,探讨

解决方案 »

  1.   

    要不然把数据导入到网页中或者是纯文本文件中用IE,或者NOTE来打印可以么???
      

  2.   

    Printer.BeginDoc;
         Printer.Canvas.TextOut(100, 100, 'Delphi Is RAD!');
         Printer.EndDoc;
      

  3.   

    自己写一个打印程序呀,基于Grid的。
    这样你就可以把任何Grid中的内容打印出来。
      

  4.   

    都是接分的?
    晕明天结帖
    另外 to Wally_wu(不想再写代码)  我参与的问题有300多,得分问题有125,我们得分率差不多
      

  5.   

    用 dev 的dbgrid和print控件
      

  6.   

    用RichEdit。
      RichEdit1.Lines.Add('-------------------');
      RichEdit1.Lines.Add('|' + 'Caption1' + '|' + 'Caption2' +  '|');
      RichEdit1.Lines.Add('|' + Fields[0].Asstring + '|' + Fields[1].asstring + '|');
        ......  RichEdit1.SelectAll;
      RichEdit1.Print('This is Report Print By RichEdit');
      

  7.   

    打印StringGrid,当然,是我作组件中碰到的问题。这个StringGrid是完全独立的,不用任何数据库,不用DataSource,代码。
    procedure TForm1.SpeedButton11Click(Sender: TObject);
    Var
      Index_R ,ALeft: Integer;
      Index : Integer;
    begin
      StringGrid_File('D:\AAA.TXT');
      if Not LinkTextFile then
      begin
        ShowMessage('失败');
        Exit;
      end;
      //
      QuickRep1.DataSet := ADOTable1;
      Index_R := ReSize(StringGrid1.Width);
      ALeft := 13;
      Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[0].Width,20,
         HeaderControl1.Sections[0].Text,taLeftJustify);
      with Create_QRDBText(DetailBand1,ALeft,8,StringGrid1.ColWidths[0],20,
             StringGrid1.Font,taLeftJustify) do
      begin
        DataSet := ADOTable1;
        DataField := ADOTable1.Fields[0].DisplayName;
      end;
      ALeft := ALeft + StringGrid1.ColWidths[0] * Index_R + Index_R;
      For Index := 1 to ADOTable1.FieldCount - 1 do
      begin
        Create_VLine(TitleBand1,ALeft - 13,16,1,40);
        Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[Index].Width,20,
          HeaderControl1.Sections[Index].Text,taLeftJustify);
        Create_VLine(DetailBand1,ALeft - 13,-1,1,31);
        with Create_QRDBText(DetailBand1,ALeft ,8,StringGrid1.ColWidths[Index] * Index_R,20,
             StringGrid1.Font,taLeftJustify) do
        begin
          DataSet := ADOTable1;
          DataField := ADOTable1.Fields[Index].DisplayName;
        end;
        ALeft := ALeft + StringGrid1.ColWidths[Index] *  Index_R + Index_R;
      end;
      QuickRep1.Preview;
    end;function TForm1.ReSize(AGridWidth: Integer): Integer;
    begin
      Result := Trunc(718 / AGridWidth);
    end;function TForm1.StringGrid_File(AFileName: String): Boolean;
    var
      StrValue : String;
      Index : Integer;
      ACol , ARow : Integer;
      AFileValue : System.TextFile;
    begin
      StrValue := '';
      Try
        AssignFile(AFileValue , AFileName);
        ReWrite(AFileValue);
        StrValue := HeaderControl1.Sections[0].Text;
        For Index := 1 to HeaderControl1.Sections.Count - 1 do
          StrValue := StrValue + ',' + HeaderControl1.Sections[Index].Text;
        Writeln(AFileValue,StrValue);
        StrValue := '';
        For  ARow := 0 To StringGrid1.RowCount - 1 do
        begin
          StrValue := '';
          StrValue := StringGrid1.Cells[0,ARow];
          For ACol := 1 To StringGrid1.ColCount - 1 do
          begin
            StrValue := StrValue + ', ' + StringGrid1.Cells[ACol,ARow];
          end;
          Writeln(AFileValue,StrValue);
        end;
      Finally
        CloseFile(AFileValue);
      end;
    end;function TForm1.LinkTextFile: Boolean;
    begin
      Result := False;
      with ADOTable1 do
      begin
        {ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
                            'Data Source= D:\;Extended Properties=Text;' +
                            'Persist Security Info=False';
        TableName := 'AAA#TXT';
        Open;       }
        if Active then
          Result := True;
      end;
    end;function TForm1.Create_QRDBText(Sender: TWinControl; ALeft, ATop, AWidth,
      AHight: Integer; AFont: TFont; AAlignMent: TAlignment): TQRDBText;
    var
      AQRDBText : TQRDBText;
    begin
      AQRDBText := TQRDBText.Create(Nil);
      with AQRDBText do
      begin
        Parent := Sender;
        Left := ALeft;
        Top := ATop;
        Width := AWidth;
        Height := AHight;
        AlignMent := AAlignMent;
        Font.Assign(AFont);
      end;
      Result := AQRDBText;
    end;function TForm1.Create_VLine(Sender: TWinControl; ALeft, ATop, AWidth,
      AHight: Integer): TQRShape;
    var
      AQRShapeV : TQRShape;
    begin
      AQRShapeV := TQRShape.Create(Nil);
      with AQRShapeV do
      begin
        Parent := Sender;
        Left := ALeft;
        Top := ATop;
        Width := AWidth;
        Height := AHight;
      end;
      Result := AQRShapeV;
    end;procedure TForm1.Create_Title(Sender: TWinControl; ALeft, ATop, AWidth,
      AHight: Integer; ACaption: String; AAlignMent: TAlignment);
    var
      AQRLabel : TQRLabel;
    begin
      AQRLabel := TQRLabel.Create(Nil);
      with AQRLabel do
      begin
        Parent := Sender;
        Left := ALeft;
        Top := ATop;
        Width := AWidth;
        AlignMent := AAlignMent;
        Caption := ACaption;
      end;
    end;
      

  8.   

    本来想自己专门一个贴子,将自己的代码完贴出来,可惜没有可用分了,只有30分,呵呵,只好借宝地一用。嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!3Q!嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻偶就不要分了。
    上边的那个可以用于任何一个StringGrid的打印,不用进行数据库连接,不需要任何的数据支持。
      

  9.   

    为什么不用Qreport?非要自己写呀?
      

  10.   

    hehe^^ ihihonline(小小->记好啊.有空多来灌水) 不错哦我的
    得分帖268 
    参与帖300我的结帖率100%还行 hehe^^
      

  11.   

    两条记录不如直接写打印机,TEXTOUT()啊
      

  12.   

    直接用Canvas的Print试试
    :)
    分是主要的!
      

  13.   

    to ihihonline(小小->记好啊.有空多来灌水) 多谢捧场你的代码我要拿回去研究研究
      

  14.   

    最简洁的是写在FORM上,然后FORM。PRINT()
      

  15.   

    第三方控件,qreport算不算用Printer来打印!
      

  16.   

    dxdbgrid savetoxls();
    就打印把!
      

  17.   

    Easy 啦!Email:[email protected]
      

  18.   

    放到窗体上,.print;
    构件结了吧