Excel := CreateOleObject('Excel.Application');
。。
 For i := 0 to Query1.RecordCount-1 Do
        Begin
          Excel.ActiveSheet.Cell[3,iCol].Value := Query1.FieldByName('CPBZSM').AsString;
          Excel.ActiveSheet.Cell[3,iCol+1].Value := '分数';
          iCol := iCol + 2;
        End;
执行到这里的时候就报错了。
提示:Project Project1.exe raised exception class EoleError with message 'Meyhod cell' not supported by automation object.' process stop.....请问各位大虾,这是为什么啊??

解决方案 »

  1.   

    是执行到这句就报错Excel.ActiveSheet.Cell[3,iCol].Value := Query1.FieldByName('CPBZSM').AsString;
      

  2.   

    Excel.ActiveSheet.Cells.item[3,iCol].Value := Query1.FieldByName('CPBZSM').AsString;
      

  3.   

    procedure speedtoexcel_user(Sinput:TwwDBGrid);
    var
      Ds_Master:Tdataset;
      ExcelApplication1:TExcelApplication;
      ExcelWorksheet1:TExcelWorksheet;
      ExcelWorkbook1:TExcelWorkbook;
      i,j:integer;
      stringlist1:Tstringlist;
      str1:string;
      range1:string;
    begin
      Ds_Master:=Sinput.DataSource.DataSet;
      if Ds_Master.IsEmpty or (not Ds_Master.Active) then
         exit
      else
        begin
          Ds_Master.DisableControls;
          Ds_Master.First;
          try
            ExcelApplication1:=TExcelApplication.Create(Application);
            ExcelWorksheet1:=TExcelWorksheet.Create(Application);
            ExcelWorkbook1:=TExcelWorkbook.Create(Application);
            ExcelApplication1.Connect;
          except
            Application.MessageBox('Excel 没有安装','系统提示',
                                   MB_IConERROR + mb_Ok);
            Abort;
          end;
        end;  try
        screen.Cursor:=crsqlwait;
        ExcelApplication1.Workbooks.Add(emptyparam,0);
        ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
        ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1]as _worksheet);
        for j :=0  to Ds_Master.FieldCount-1 do
        begin
          ExcelWorksheet1.Cells.Item[1,j+1]:=Ds_Master.Fields[j].DisplayLabel;
          ExcelWorksheet1.Cells.Item[1,j+1].font.size:='14';
        end;
        stringlist1:=Tstringlist.Create;
        clipboard.Clear;
        with Ds_Master do
        begin
          open;
          first;
        end;
        while not Ds_Master.Eof do
        begin
          str1:='';
          for i := 0 to Ds_Master.FieldCount-1 do
          begin
            str1:=str1+Ds_Master.Fields[i].AsString+#9;
            Application.ProcessMessages;
          end;
          stringlist1.Add(str1);
          Ds_Master.Next;
        end;
        //dataset.Free;
        //dataset.Refresh;
        clipboard.AsText:=stringlist1.Text;
         i:=Ds_Master.FieldCount;
        j:=Ds_Master.RecordCount+1;       //ExcelWorksheet1.Cells.i
        //i:=cells.
        //ExcelWorksheet1.Paste;  //从A1开始粘贴
        //srt1:=ExcelWorksheet1.Cells.Item[i,j];
        //ExcelWorksheet1.Range['a2','z1000'].PasteSpecial(0,0,0,0);
        //ExcelWorksheet1.Range['a2','b4'].PasteSpecial(0,0,0,0);
        //i:=ExcelWorksheet1.Cells.Row[2];
        //j:=ExcelWorksheet1.Cells.Rows.Column;
       //fortest:=string(ExcelWorksheet1.Cells.Name);
        //fortest:=ExcelWorksheet1.Cells.Item[j,i];
        //fortest:=string(ExcelWorksheet1.Cells.Range[i,j] );
        //ExcelWorksheet1.Range['a2'].PasteSpecial(0,0,0,0);
        range1:=excelrange(j,i);
        ExcelWorksheet1.Range['a2',range1].PasteSpecial(0,0,0,0);
        stringlist1.Free;
        clipboard.Clear;
        ExcelWorksheet1.Columns.AutoFit;
        ExcelApplication1.Disconnect;
        ExcelApplication1.Visible[0]:=true;
        screen.Cursor:=crdefault;
        //dataset.Refresh;
        Ds_Master.EnableControls;
        Application.MessageBox('数据转换成功!','系统',
                      MB_ICONINFORMATION+Mb_ok);
                      
      except
        stringlist1.Free;
        clipboard.Clear;
        ExcelApplication1.Disconnect;
        ExcelApplication1.Quit;
        ExcelApplication1.Free;
        ExcelWorkbook1.Free;
        ExcelWorksheet1.Free;
        screen.Cursor:=crdefault;
        Application.MessageBox('错误!','数据转换失败!',
                    Mb_iconerror+Mb_ok);
        Ds_Master.EnableControls;
      end;
     end;
      

  4.   

    看一下http://bbs.2ccc.com/topic.asp?topicid=92461
    可以解决你的问题
      

  5.   

    excelapp := CreateOleObject('Excel.Application');
    excelapp.visible := true;
    excelapp.workbooks.add;
    ....
    For i := 0 to Query1.RecordCount-1 Do
    Begin
      Excelapp.Cells[3,iCol].Value := Query1.FieldByName('CPBZSM').AsString;
      Excelapp.Cells[3,iCol+1].Value := '分数';
      iCol := iCol + 2;
    End;
      

  6.   

    多谢,各位! xdf221(xdf221) 兄你的我试了不行,zgq19801123(小强) 兄的可以:)