代码如下: with   Dbgridname.DataSource.DataSet   do
                                  begin   
                                      pBookMark   :=   GetBook;   
                                      DisableControls;   
                                      for   I:=0   to   dbgridname.Columns.Count-1   do   
                                      begin   
                                            if   dbgridname.Columns[I].Visible=False   then   
                                                  Continue;   
                                            Sheet.Cells[J,I+1]   :=   dbgridname.Columns[I].Title.Caption;   
                                      end;   
                                      Inc(J);   
                                      First;   
                                      while   not   Eof   do     begin   
                                                  for   I:=0   to   dbgridname.Columns.Count-1   do   begin   
                                                          if   dbgridname.Columns[I].Visible=False   then   
                                                                Continue;   
                                        
Sheet.Cells[J,I+1]:=trim(dbgridname.DataSource.DataSet.Fieldbyname(dbgridname.Columns[i].FieldName).asstring);//asstring 不能转换为文本的吗?   
                                    //改变颜色,字体颜色和底色   
                                  Sheet.Cells[J,I+1].font.ColorIndex:=3;
                                  Sheet.Cells[J,I+1].Select;   
                                  sheet.Cells[J,I+1].Interior.ColorIndex:=50
                                                  end;   
                                                  Inc(J);   
                                                  Next;   
                                      end;   
                                      GotoBook(pBookMark);   
                                      FreeBook(pBookMark);   
                                      EnableControls;   
                                  end;   
                                  XLApp.activeworkbook.saveas(StrSaveFile);   
                                  Application.ProcessMessages;   
                                  XLApp.Application.Quit;   
                          end;