修改的一个导出DataSet到xls的单元[5]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 cornermoss 的 blog

emptyparam);
      wksheetres.activate(lcid_res);
      wksheetres.range[pos_lefttop, pos_rightbottom].select;
      wksheetres.paste(emptyparam, emptyparam, lcid_res);
      wksheetres.columns.autofit;
      wksheetres.range['a1','a1'].select;
      wksheetres.name := strname+'__'+inttostr(i);
    end;
  finally
    try
      (wkbookres.sheets[1] as _worksheet).activate(lcid_res);
      wkbookres.close(not(bdontsave) ,path+'\'+filename,emptyparam,lcid_res);
      xlsappres.quit;
      xlsappres.disconnect;
    finally
      //杀死未关闭的excel进程
      xlsapphwnd := findwindow( nil,_xlsrescaption );
      if xlsapphwnd<>0 then sendmessage( xlsapphwnd, wm_close, 0, 0);
    end;
    try
      //wkbooktmp.saved[lcid_tmp]:=true;
      xlsapptmp.quit;
      xlsapptmp.disconnect;
    finally
      xlsapphwnd := findwindow( nil,_xlstmpcaption );
      if xlsapphwnd<>0 then sendmessage( xlsapphwnd, wm_close, 0, 0);
    end;
  end;
end;

function dbgridtoxlsex(grid:tdbgrid;fname:string; bsetfieldname:boolean;callfunc:texportxls_callbackproc;const baskforstop:boolean; const bneedunite:boolean ):integer;
var
  c,r,i :integer;
  xls:txlswriter;
  ntotalcount, ncurrentcount : integer;
  bdontsave:boolean;
  nonesheetmaxrecord : integer;
  path, filename, tmpfile:string;
  bnoteof : boolean;
begin
  g_xlswriterisruning := true;
  result := 0;
  bdontsave := false;
  ntotalcount := grid.datasource.dataset.recordcount;
  ncurrentcount := 0;
  splitstrtotwopartbylastflag(fname,'\/',path,filename);
  grid.datasource.dataset.disablecontrols;
  bnoteof := true;
  try
    while bnoteof do
    begin
      inc(result);
      tmpfile := path+'\$$$'+inttostr(result)+filename;
      deletefile(tmpfile);
      xls:=txlswriter.create(tmpfile,grid.fieldcount+1, 65530 );    //65530
      if grid.fieldcount > xls.maxcols then
        xls.maxcols := grid.fieldcount+1;
      try
        xls.writebof;
        xls.writedimension;
        if bsetfieldname then
        begin
          for c:=0 to grid.fieldcount-1 do
            xls.cellstr(0,c,grid.fields[c].fieldname);
          r :=2;
        end
        else r:=1;
        for c:=0 to grid.fieldcount-1 do
          xls.cellstr(r-1,c,grid.fields[c].displaylabel);

本文关键:修改的一个导出DataSet到xls的单元
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top