本人做一个数据转换,将SQL中的数据(表)转为EXCEL格式,程式如下:procedure TForm1.EXCEL1Click(Sender: TObject);
 var
   Tempdg:TDBGRIND;
   rangeE: excelrange;
   i,row:integer;
   book:TbookStr;
begin
  excelapplication1.Visible[0]:=true;
  excelapplication1.Workbooks.Add(NULL,0);//生成页
  rangeE:=excelapplication1.activecell;
  for i:=0 to query1.Fields.Count-1 do
   begin
    rangeE.value:=Tempdg.Columns[i].Title.Caption;//建立标题
    rangeE:=rangeE.next;
   end;
   query1.DisableControls;
   try
     book:=query1.Book;
     try
      query1.First;
      row:=2;
      while not query1.Eof do
       begin
         rangeE:=excelapplication1.range['A'+inttostr(row),'A'+inttostr(row)];
         for i:=0 to query1.Fields.Count-1 do
           begin
             rangeE.Value:=query1.Fields[i].Value;//填充数据
             rangeE.next;
           end;
         query1.Next;
         inc(row);
       end;
      finally
       query1.Book:=book;
       end;
   finally
     query1.enablecontrols;
 end;
  rangeE:=excelapplication1.range['A1','E'+inttostr(row-1)];
  rangeE.Autoformat(3,NULL,NULL,NULL,NULL,NULL,NUll);
 end;运行后只有标题可见,数据没有,我用的 TQUERY 没有建立永久字段对象(是不是这个原因,我怀疑),请大侠不吝赐教。