Delphi 控制Excel(2)

看看我的函数
function ExportToExcel(Header: String;
 
vDataSet: TDataSet): Boolean;
var
  I,VL_I,j: integer;
  S,SysPath: string;
  MsExcel:Variant;
begin
  Result:=true;
  ifApplication.MessageBox('您确信将数据导入到Excel吗?','提示!',MB_OKCANCEL +MB_DEFBUTTON1) = IDOK then
  begin
     SysPath:=ExtractFilePath(application.exename);
     with TStringList.Create do
     try
       vDataSet.First ;
       S:=S+Header;
   //   system.Delete(s,1,1);
       add(s);
       s:=';
       For I:=0 to vDataSet.fieldcount-1 do
         begin
           If vDataSet.fields[I].visible=true then
              S:=S+#9+vDataSet.fields[I].displaylabel;
         end;
       system.Delete(s,1,1);
       add(s);
       while not vDataSet.Eof do
       begin
         S := ';
         for I := 0 to vDataSet.FieldCount -1 do
           begin
             If vDataSet.fields[I].visible=true then
                S := S + #9 + vDataSet.Fields[I].AsString;
           end;
         System.Delete(S, 1, 1);
         Add(S);
         vDataSet.Next;
       end;
       Try
         SaveToFile(SysPath+'\Tem.xls');

你可能感兴趣的:(Excel)