当前查询的数据是利用AppServer结构得到的, 并且在ListView中显示出来了
但我不知道怎么输出到报表中,请各位有经验的高手谈谈方法,要多少分就给先给50

解决方案 »

  1.   

    我这里有个使用 excel的例子,给你参考。
      

  2.   

    use ComObj,Excel2000;//使用Excel生成报表
    Procedure TMainForm.ExcelReport(var Office:Variant;DS:TDataSet;title:String);
    var
      sheet:Variant;
      i,j,m,row,column:integer;
      s:string;
      bm:TbookMark;
    begin
      if Ds.Active = false then
        Raise Exception.Create('生成报表时错误,数据表不在打开状态。执行查询或统计之后才能生成报表。');
      if Ds.RecordCount = 0 then
        Raise Exception.Create('生成报表失败。当前零条记录。');
      try
      Office:=CreateOleObject('Excel.Application');
      Except
        Raise Exception.Create('打开Excel时错误。报表功能需要安装Excel,如果已安装Excel则可能需要重新安装。'); end;  bm:=Ds.GetBook ;
      Try
      Ds.DisableControls ;
      Try
      row:=Ds.RecordCount ;
      Column:=Ds.FieldCount ;  if not (Ds = Dm.Aqy) then
        Office.visible:=true;
      Office.WorkBooks.add;
      Sheet:=Office.ActiveSheet;
      j:=ord('a')+DS.FieldCount - 1 ;
      s:='a1:'+Chr(j)+'1';
      sheet.range[s].select;
      Office.selection.merge;
      Sheet.cells[1,1].Value:=Title;//'请在这里输入你的报表名称';
      sheet.rows['1:1'].rowheight:=40;
      Sheet.cells[1,1].font.bold:=true;
      Sheet.cells[1,1].font.size:=16;
      Sheet.cells[1,1].HorizontalAlignment:=xlCenter;
      Sheet.cells[1,1].VerticalAlignment:=xlCenter;
      //设置边框样式
      s:='a2:'+chr(j)+inttostr(Row+2);
      Sheet.range[s].select;
      Office.Selection.NumberFormatLocal:='@';
      Office.selection.Borders[xlDiagonalDown].LineStyle := xlNone;
      Office.selection.Borders[xlDiagonalUp].LineStyle := xlNone;
      Office.Selection.Borders[xlEdgeLeft].LineStyle := xlContinuous;
      Office.Selection.Borders[xlEdgeLeft].Weight := xlThin;
      Office.Selection.Borders[xlEdgeLeft].ColorIndex := xlAutomatic;
      Office.Selection.Borders[xlEdgeTop].LineStyle := xlContinuous;
      Office.Selection.Borders[xlEdgeTop].Weight :=xlThin ;
      Office.Selection.Borders[xlEdgeTop].ColorIndex :=xlAutomatic ;
      Office.Selection.Borders[xlEdgeBottom].LineStyle :=xlContinuous ;
      Office.Selection.Borders[xlEdgeBottom].Weight :=xlThin ;
      Office.Selection.Borders[xlEdgeBottom].ColorIndex :=xlAutomatic ;
      Office.Selection.Borders[xlEdgeRight].LineStyle :=xlContinuous ;
      Office.Selection.Borders[xlEdgeRight].Weight :=xlThin ;
      Office.Selection.Borders[xlEdgeRight].ColorIndex :=xlAutomatic ;
      Office.Selection.Borders[xlInsideVertical].LineStyle :=xlContinuous ;
      Office.Selection.Borders[xlInsideVertical].Weight :=xlThin ;
      Office.Selection.Borders[xlInsideVertical].ColorIndex :=xlAutomatic ;
      Office.Selection.Borders[xlInsideHorizontal].LineStyle :=xlContinuous ;
      Office.Selection.Borders[xlInsideHorizontal].Weight :=xlThin ;
      Office.Selection.Borders[xlInsideHorizontal].ColorIndex :=xlAutomatic ;  //设置货币,日期等特殊格式
      for i:=0 to Ds.FieldCount - 1 do begin
        Sheet.cells[2,i+1].value:=Ds.Fields[i].DisplayLabel ;
        s:=Chr(ord('a')+i)+':'+Chr(ord('a')+i);
        if Ds.Fields[i].FieldType = dtDateTime then
          Sheet.Columns[s].NumberFormatLocal := 'yyyy-mm-dd';
      end;  j:=0;
      Ds.First;
      //开始填充数据
      while not Ds.Eof do begin
        j:=j+1;
        m:=ord('a')+DS.FieldCount - 1 ;
        s:='a'+inttostr(j+2)+':'+Chr(m)+inttostr(j+2);
        sheet.range[s].Select;
        for i:=0 to Column - 1 do begin
          Sheet.cells[j+2,i+1].value:=Ds.Fields[i].value ;
        end;
        Ds.next;
      end;  //设置自动列宽
      for i:=0 to Ds.FieldCount - 1 do begin
        s:=Chr(ord('a')+i)+':'+Chr(ord('a')+i);
        Sheet.Columns[s].EntireColumn.AutoFit;
      end;  { 页面设置,我的电脑没有打印机不能用 }
      //Sheet.PageSetup.CenterFooter:='第 &P 页,共 &N 页';
      //Sheet.PageSetup.RightFooter:='&D';  Sheet.cells[1,1].activate;
      Application.ProcessMessages ;
      Finally
        Ds.GotoBook(bm);
        Ds.FreeBook(bm);
      end;
      Finally
        Ds.EnableControls ;
      end;
    end;
      

  3.   

    生成CVS文件,然后用Excel宏来分析.(比较流行的做法)