我用midas开发了一套管理软件,其中把数据集导出excel时,好多机器都没有问题,但有的却不行,导出时提示,interface not support.(接口不支持).
ExcelApplication1、ExcelWorkbook1、ExcelWorksheet1为控件.
请问是不是系统环境是不是缺少文件啊.我的函数是这样写的:
//保存数据到EXCEL
Procedure TSysdb.PubP_DataSaveToExcel(TblName:TdataSet;
  Const Tilte:string='';ShowCol:boolean=false);
var i,j,k:integer;
   V:array of array of  variant;
begin
  if not SaveDialog1.Execute then exit;
  application.ProcessMessages;
  screen.Cursor :=crSQLWait;
  try
   try
    ExcelApplication1.Connect;
    ExcelApplication1.Visible[0]:=false;
    ExcelApplication1.Workbooks.Add(NULL,0);
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
    ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _WorkSheet);
   except
    application.MessageBox('导出出错,请确认EXCEL97或EXCEL2000是否已按装!',CON_PROMPT,MB_OK+MB_ICONSTOP);
   end;
    with TblName do
    begin
      disablecontrols;
      if not ShowCol then
         V := VarArrayCreate([0,RecordCount+5,0,Fields.Count], varVariant)
      else
         V := VarArrayCreate([0,2*RecordCount+5,0,Fields.Count], varVariant);
      i :=2;
      j :=0;
      k :=0;
      V[0][2] := Tilte;
      if not ShowCol then //显示单标题
        for j:=0 to Fields.Count-1 do
        if Fields[j].visible then //取到标题
        begin
          V[i][k] := Fields[j].displaylabel;
          k := k+1;
        end;
      first;  
      while not eof do
      begin
        k:= 0;
        if not ShowCol then //显示单标题
          i:= i+1
        else
          i:= i+2;
        for j:=0 to Fields.Count-1 do
        begin
          if Fields[j].visible then
          begin
           if not ShowCol then //显示单标题
           begin
             if Fields[j] is TStringField then
               V[i][k] := ''''+Fields[j].AsString//取到数据
             else
               V[i][k] := Fields[j].value;//取到数据
             k :=k+1;
           end
           else
           begin
             V[i][k] := Fields[j].displaylabel;
             if Fields[j] is TStringField then
               V[i+1][k] := ''''+Fields[j].AsString//取到数据
             else
               V[i+1][k] := Fields[j].value;//取到数据
             k :=k+1;
           end;
          end;
        end;
        next;
      end;
      if not ShowCol then //显示单标题
      begin
       if Fields.Count<26 then
         ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),RecordCount+5])].Value := V
       else
         ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),RecordCount+5])].Value := V;
      end
      else
      begin
       if Fields.Count<26 then
         ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Fields.Count),2*RecordCount+5])].Value := V
       else
         ExcelWorksheet1.Range['A1', Format('%s%d',[Chr(Ord('A')+Trunc(Fields.Count/26)-1)+Chr(Ord('A')+(Fields.Count mod 26)),2*RecordCount+5])].Value := V;
      end;
      first;
      enablecontrols;
    end;
    ExcelWorksheet1.SaveAs(SaveDialog1.FileName);
    ExcelApplication1.Disconnect;
    ExcelApplication1.Quit;
  finally
    screen.Cursor := crdefault;
  end;
end;

解决方案 »

  1.   

    每个机器上都已装了excel2000,这个是没有疑问的.我想是缺少什么excel组件有关,因为我发现有一台机器原来的可以导出的,后来重装系统后,就导不出了,那装excel还是什么不同吗?
      

  2.   

    有可能是中病毒了,我也遇到过,调用word时interface not support,本来以为是word版本的问题后来重装也不行,去网上搜了一下"word打不开",发现原来是病毒,打了补丁后就好了.
      

  3.   

    我是菜鸟,以前做毕业设计时遇到过类似的问题。
    我那毕业设计是两层的,将数据倒到excel 中出现excel 启动运行起来,里面却没有倒出的数据,好象我是在连接数据库时将ADOConnection (偶菜,已经记不清是不是这个组件了,或者是datamodule)先free掉,在重新创建。