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

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

本文简介:选择自 cornermoss 的 blog

constructor tuniteseveralxlstoonethread.create(const _tmpflag, _path, _filename:string;const _istart, _iend : integer);
begin
  inherited create(true);
  tmpflag := _tmpflag;
  path := _path;
  filename := _filename;
  istart := _istart;
  iend := _iend;
  mcompleted := false;
  resume();
end;

destructor tuniteseveralxlstoonethread.destroy;
begin
  inherited;
end;

procedure tuniteseveralxlstoonethread.execute;
const
  _headletterofxls:array [1..52]of string    //注意这里只定义了52列,需要增加就自己动手,最多256列
            = ('a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z',
               'aa','ab','ac','ad','ae','af','ag','ah','ai','aj','ak','al','am',
               'an','ao','ap','aq','ar','as','at','au','av','aw','ax','ay','az');
  _xlsrescaption= 'fkulwjs_sksla_892x_res';
  _xlstmpcaption= 'fkulwjs_sksla_892x_tmp';
var
  xlsappres, xlsapptmp: texcelapplication;
  wkbookres, wkbooktmp : _workbook;
  wksheetres, wksheettmp : _worksheet;
  lcid_res, lcid_tmp:integer;
  pos_lefttop, pos_rightbottom : string; //xls中左上、右下位置
  xlsapphwnd:thandle;
  bdontsave : boolean;
  i : integer;

  strname,strext:string; //文件名及扩展名
begin
  freeonterminate := true;
  if terminated then exit;
  splitstrtotwopartbylastflag(filename, '.', strname, strext);
  try
    screen.cursor := crhourglass;
    bdontsave := false;
    xlsappres := texcelapplication.create(nil);
    with xlsappres do
    begin
      connect;
      visible[0]:=false;
      lcid_res:=getuserdefaultlcid();
      displayalerts[lcid_res]:=false;
      caption:=_xlsrescaption;
      wkbookres:=workbooks.add(emptyparam,lcid_res);
    end;
    xlsapptmp := texcelapplication.create(nil);
    with xlsapptmp do
    begin
      connect;
      visible[0]:=false;
      lcid_tmp :=getuserdefaultlcid();
      displayalerts[lcid_tmp]:=false;
      caption:=_xlstmpcaption;
    end;
    for i:=istart to iend do
    begin
      if i<=3 then wksheetres:=wkbookres.sheets[i] as _worksheet
      else
      begin
        wkbookres.sheets.add(emptyparam, wksheetres, 1, emptyparam, lcid_res);
        wksheetres := wkbookres.sheets[i] as _worksheet;
      end;
      wkbooktmp:= xlsapptmp.workbooks.open(path+'\'+tmpflag+inttostr(i)+filename, emptyparam,emptyparam,
                    emptyparam,emptyparam,emptyparam,emptyparam,
                    emptyparam,emptyparam,emptyparam,emptyparam,
                    emptyparam,emptyparam,lcid_tmp);
      pos_lefttop := 'a1';
      wksheettmp := xlsapptmp.activesheet as _worksheet;
      pos_rightbottom := _headletterofxls[wksheettmp.usedrange[lcid_tmp].columns.count]+inttostr(wksheettmp.usedrange[lcid_tmp].rows.count);
      xlsapptmp.range[pos_lefttop, pos_rightbottom].copy(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;
 

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

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

go top