有个报表,要横向罗列查询几十个字段,页面因此根本就排不下
例如就像下面的格式:
员工编号 员工姓名 生产产品 产生废品1 产生废品2 产生废品70

因此,要有选择性地从这70个废品中选择几个关键的,否则横向排不下,也没有必要把所有的废品都打出来。不知道怎么处理了?

解决方案 »

  1.   

    zczb(zczb)
    老大,帮帮忙吧,我想不出办法来了
    我用BCB
      

  2.   

    zczb(zczb)
    你这不是捉弄人么?你说你做出来了,到这里说了一下,然后就是不告诉我。唉
      

  3.   

    clientdataSet ,可以隐藏点不想显示的列
      

  4.   

    我搞了个通用的打印数据网格的报表。
    打印函数如下(delphi的,其实在此之前还有一个界面用收集用户的打印参数,传进去一个记录集,一个Fields数组,在这个数组里面设置是不是显示各字段,你可以看一下):procedure PreviewB(FDataSet:TDataSet; Fields:Array of TRptField; SettingInfo:TPrintSetInfo);
    var Report:TPrintDBGridReport;  i:integer;
    begin
       if FDataSet.IsEmpty then exit;
       Report:=TPrintDBGridReport.Create(Application.MainForm);
       with Report do
        begin
           Tag:=0;
           AutoFitPrint(SettingInfo);
           InitPrintInfoB(FDataSet, Fields, SettingInfo);
           Preview;
           free;
        end;
    end;procedure TPrintDBGridReport.AutoFitPrint(SettingInfo:TPrintSetInfo);
    var i:integer;
    begin
      self.ReportTitle:=SettingInfo.Title;
      self.PrinterSettings.PrinterIndex:=SettingInfo.PrinterIndex;
      self.Page.TopMargin:=SettingInfo.TopMargin;
      self.Page.BottomMargin:=SettingInfo.BottomMargin;
      self.Page.LeftMargin:=SettingInfo.LeftMargin;
      self.Page.RightMargin:=SettingInfo.RightMargin;
      self.Page.PaperSize:=TQRPaperSize(SettingInfo.PaperSizeIndex);
      self.Page.Orientation:=SettingInfo.Orientation;
      self.Zoom:=SettingInfo.Zoom;
    end;procedure TPrintDBGridReport.InitPrintInfoB(FDataSet: TDataSet;
      Fields: array of TRptField; SettingInfo:TPrintSetInfo);
    var ColText:TQRLabel;DBText:TQRDBText;Shape:TQRShape;
        i:integer; FLeft:integer; FirstLine:boolean;
    begin
       FLeft:=0;
       self.DataSet:=FDataSet;
       PageHeaderBand1.Height:=SettingInfo.TitleHeight;
       self.ColumnHeaderBand1.Height:=SettingInfo.HeaderHeight;
       self.DetailBand1.Height:=SettingInfo.BodyHeight;
       FirstLine:=True;
       for i:=0 to high(Fields) do
        begin
          if not Fields[i].Visible then continue;
          ColText:=TQRLabel.Create(self);
          ColText.Parent:=self.ColumnHeaderBand1;
          ColText.Left:=FLeft+4;
          ColText.Top:=4;
          ColText.AutoSize:=false;
          if Fields[i].Width>6 then ColText.Width:=Fields[i].Width-6 else ColText.Width:=Fields[i].Width;
          ColText.Caption:=Fields[i].DispName;
          ColText.Alignment:=taCenter;
          ColText.Font:=SettingInfo.HeaderFont;      if SettingInfo.BodyLineShow then
          begin
              Shape:=TQRShape.Create(self);
              Shape.Parent:=self.ColumnHeaderBand1;
              Shape.Left:=FLeft;
              Shape.Shape:=qrsVertLine;
              Shape.Pen.Color:=SettingInfo.HeaderLineColor;
              if FirstLine then Shape.Pen.Width:=SettingInfo.HeaderLineWidth else Shape.Pen.Width:=1;
              Shape.Width:=Shape.Pen.Width;
              Shape.Top:=0;
              Shape.Height:=self.ColumnHeaderBand1.Height;
          end;      DBText:=TQRDBText.Create(self);
          DBText.Parent:=self.DetailBand1;
          DBText.Left:=FLeft+4;
          if FirstLine then DBText.Left:=DBText.Left+SettingInfo.HeaderLineWidth-1;
          DBText.Top:=2;
          DBText.AutoSize:=false;
          if Fields[i].Width>6 then DBText.Width:=Fields[i].Width-6 else DBText.Width:=Fields[i].Width;
          DBText.DataSet:=DataSet;
          DBText.DataField:=Fields[i].DispName;
          DBText.Font:=SettingInfo.BodyFont;
          case Fields[i].Alignment of
          1: DBText.Alignment:=taRightJustify;
          2: DBText.Alignment:=taCenter;
          else DBText.Alignment:=taLeftJustify;
          end;      if SettingInfo.BodyLineShow then
          begin
              Shape:=TQRShape.Create(self);
              Shape.Parent:=self.DetailBand1;
              Shape.Left:=FLeft;
              Shape.Shape:=qrsVertLine;
              Shape.Pen.Color:=SettingInfo.BodyLineColor;
              if FirstLine then Shape.Pen.Width:=SettingInfo.HeaderLineWidth else Shape.Pen.Width:=SettingInfo.BodyLineWidth;
              Shape.Width:=Shape.Pen.Width;
              Shape.Top:=0;
              Shape.Height:=self.DetailBand1.Height;
          end;      FLeft:=FLeft+Fields[i].Width;
          FirstLine:=false;
        end;
        //标题
        lbl_Title.Caption:=SettingInfo.Title;
        lbl_Title.Font:=SettingInfo.TitleFont;
        i:=(FLeft-lbl_Title.Width) div 2;
        if i<self.ColumnHeaderBand1.Left then i:=self.ColumnHeaderBand1.Left;
        lbl_Title.Left:=i;    if SettingInfo.BodyLineShow then
        begin
            Shape:=TQRShape.Create(self);
            Shape.Parent:=self.ColumnHeaderBand1;
            Shape.Left:=FLeft;
            Shape.Shape:=qrsVertLine;
            Shape.Pen.Color:=SettingInfo.HeaderLineColor;
            Shape.Pen.Width:=SettingInfo.HeaderLineWidth;
            Shape.Width:=Shape.Pen.Width;
            Shape.Top:=0;
            Shape.Height:=self.ColumnHeaderBand1.Height;        Shape:=TQRShape.Create(self);
            Shape.Parent:=self.DetailBand1;
            Shape.Left:=FLeft;
            Shape.Shape:=qrsVertLine;
            Shape.Pen.Color:=SettingInfo.BodyLineColor;
            Shape.Pen.Width:=SettingInfo.HeaderLineWidth;
            Shape.Width:=Shape.Pen.Width;
            Shape.Top:=0;
            Shape.Height:=self.DetailBand1.Height;        Shape:=TQRShape.Create(self);
            Shape.Parent:=self.DetailBand1;
            Shape.Shape:=qrsHorLine;
            Shape.Left:=SettingInfo.BodyLineWidth;
            Shape.Top:=DetailBand1.Height-2;
            Shape.Width:=FLeft-SettingInfo.BodyLineWidth;
            Shape.Pen.Width:=SettingInfo.BodyLineWidth;
            Shape.Pen.Color:=SettingInfo.BodyLineColor;
            Shape.Height:=Shape.Pen.Width;
        end;    if SettingInfo.HeaderLineShow then
        begin
            Shape:=TQRShape.Create(self);
            Shape.Parent:=self.ColumnHeaderBand1;
            Shape.Shape:=qrsHorLine;
            Shape.Left:=SettingInfo.HeaderLineWidth;
            Shape.Top:=-1;
            Shape.Width:=FLeft-SettingInfo.HeaderLineWidth;
            Shape.Pen.Width:=SettingInfo.HeaderLineWidth;
            Shape.Pen.Color:=SettingInfo.HeaderLineColor;
            Shape.Height:=Shape.Pen.Width;        Shape:=TQRShape.Create(self);
            Shape.Parent:=self.ColumnHeaderBand1;
            Shape.Shape:=qrsHorLine;
            Shape.Left:=SettingInfo.HeaderLineWidth;
            Shape.Top:=ColumnHeaderBand1.Height-3;
            Shape.Width:=FLeft-SettingInfo.HeaderLineWidth;
            Shape.Pen.Width:=SettingInfo.HeaderLineWidth;
            Shape.Pen.Color:=SettingInfo.HeaderLineColor;
            Shape.Height:=Shape.Pen.Width;        Shape:=TQRShape.Create(self);
            Shape.Parent:=self.QRBand1;
            Shape.Shape:=qrsHorLine;
            Shape.Left:=SettingInfo.HeaderLineWidth;
            Shape.Top:=-2;
            Shape.Width:=FLeft-SettingInfo.HeaderLineWidth;
            Shape.Pen.Width:=SettingInfo.HeaderLineWidth;
            Shape.Pen.Color:=SettingInfo.HeaderLineColor;
            Shape.Height:=Shape.Pen.Width;
        end;
    end;
      

  5.   

    这样你就可以在打印前整理好记录集,然后传进去,动态生成各个DBText。 挺笨的,但我想不出更好的办法来。
      

  6.   

    还有一个办法类似,就是用fastreport, 选整好记录集,该隐藏的就在记录集中去掉,然后用fastreport的打印交叉表的方法(我认为就是根据记录集动态打印),demo中有一个例子,这样你就不用自己去画报表了。
      

  7.   

    我有一个可以动态打印工资条的代码程序,可靠打印的字段数,觉得宽度不够的话,可以拖动在Grid上面拖动调整,,还可以加页眉和页脚,主要是满足打印工资条用的,可以打出多列头,不过是基于Reportmachine,稍加改造立马可以在FastReport上用,很久的代码不知道在那,我去找一找,当初就是觉得EhLib中的打印GRID不能满足需求才开发的