我想做一个自动报表的东西,就是从一些子表中提出一些数据
然后写到汇总表中,请问如何实现.最好有例子.分不够可再加.
请高手不吝赐教.

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1467/1467372.xml?temp=.1967737
      

  2.   

    我想在程序中打开两个EXCEL表,将其中的一个表中的数据进行运算,把得到的结果写到另一个表中,请问如何实现.我用的是DELPHI自带的主件,编译通过.但执行时出错,提示接口错误.请问为何?谁能给个例子最好!谢谢!!!
      

  3.   

    用Ado连接Excel
    ConnectExcelAdoDataSet(FileName:String) 
    begin
    ConnectStr:String;
    //TempResult:Boolean;
    begin
      Result:=False;
      ExcelAdoConnection.Connected:=False;
      try
       ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite;Extended Properties=Excel 8.0;';
       ConnectStr:=ConnectStr+'Data Source='+FileName+';';
       ConnectStr:=ConnectStr+'Persist Security Info=False';
       ExcelAdoConnection.ConnectionString:='';
       ExcelAdoConnection.ConnectionString:=ConnectStr;
       ExcelAdoConnection.LoginPrompt:=False;
       ExcelAdoConnection.Connected:=True;
       if ExcelAdoConnection.Connected=True then
         begin
           Result:=True;
         end
       else
         begin
           try
             ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite;Extended Properties=Excel 7.0;';
             ConnectStr:=ConnectStr+'Data Source='+FileName+';';
             ConnectStr:=ConnectStr+'Persist Security Info=False';
             ExcelAdoConnection.ConnectionString:='';
             ExcelAdoConnection.ConnectionString:=ConnectStr;
             ExcelAdoConnection.LoginPrompt:=False;
             ExcelAdoConnection.Connected:=True;
             if ExcelAdoConnection.Connected=True then
               begin
                 Result:=True;
               end;
           except
              Result:=False;
           end;
        end;
      except
        Result:=False;
      end;
      Result:=Result;
    end;
    这是连接Excel的函数,if ConnectExcelAdoDataSet(//Excel文件名) then
        begin
          with ExcelADODataSet do
            begin
              CommandType:=cmdTable;
              CommandText:='[Sheet1$]';
              Active:=True;
            end;
        end
      else
        begin
          MessageBox(Application.Handle,'打开文件失败!','系统提示',MB_ICONINFORMATION or MB_OK);
          exit;
        end;建立两个Ado对两个Excel表进行操作就行了!
      

  4.   

    我在网上看到有人用ADO做,有人用DELPHI自带组件做,用什么做好,请给个建议
    我现在用的是组件,请给个例子,谢谢!
      

  5.   

    // 判断是否有Execl,且将其打开
    function  OpenExcel(ExcelApplication: TExcelApplication):boolean;
    begin
      Result := True;
      try
        ExcelApplication.Connect;
        ExcelApplication.Visible[1] := True;
        if not (ExcelApplication.Workbooks.Count > 0) then
        begin
          ExcelApplication.Workbooks.add(emptyparam,1);
        end;
        CellRow := 1;
        CellCol := 1;
      except
        Application.MessageBox('您没有安装Excel,请安装后再使用','提示',mb_ok);
        Result := False;
      end;
    end;
      

  6.   

    //输出到 Excel 文件
    procedure OutputExcel(ExcelApplication: TExcelApplication;DataSet: TQuery;Flag: integer);
    var
      Sheet1 : OleVariant;     // Excel文件中的一页
      j : integer;             //循环控制表量
      FieldNum: integer;       //字段个数
    begin
      Sheet1 := ExcelApplication.Workbooks[1].Sheets[1];
      Sheet1.visible := true;
      if Flag = 0 then
      begin
        FieldNum := DataSet.FieldCount -1;
      end
      else
      begin
        FieldNum := DataSet.FieldCount -3;
      end;
      for j := 0 to FieldNum do  // 输出标题
      begin
        Sheet1.Cells[CellRow,CellCol + j] := '''' + DataSet.Fields[j].DisplayLabel;
        Sheet1.Cells[cellrow,CellCol + j].Font.Name := '宋体';
        Sheet1.Cells[cellrow,CellCol + j].Font.Size := '12';
        Sheet1.Cells[cellrow,CellCol + j].Font.Bold := True;
      end;
      DataSet.First;
      while not DataSet.Eof do      // 输出内容
      begin
        Inc(CellRow);
        for j := 0 to FieldNum do
        begin
          Sheet1.Cells[Cellrow,CellCol+j].Font.Name := '宋体';
          Sheet1.Cells[cellrow,CellCol+j].Font.Size := '9';
          Sheet1.Cells[CellRow,CellCol+j] := '''' + DataSet.Fields[j].AsString;
        end;
        DataSet.Next;
      end;
    end;
      

  7.   

    可以使用f1book控件,使用控件的好处是使你的程序有处理excel文件的能力,而不需要安装
    office
      

  8.   

    各位大侠,我在程序中用的是DELPHI提供的组件,给EXCEL表格赋值还没问题,但是和别的
    组件联系时,如给TEDIT赋值为EXCEL表中的值时,编译则产生错误,“PROJECT XX。EXE 
    RAISE EXCEPTION CLASS EINTFCASTERROR WITH MESSAGE ‘INTERFACE NOT SUPPORTED’”
    请问为何,应如何解决。谢谢!
      

  9.   

    http://expert.csdn.net/Expert/topic/2304/2304020.xml?temp=.7317774
    好多的人在这里回答的