procedure TFmKhXz.SaveToExcel;
var
ExcelApp,Sheet:Olevariant;
rowcnt:integer;
bk:TBookMark;
begin
try
bk:=dxSelect.GetBookmark;
if dxSelect.IsEmpty then Exit;
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.visible:=true;
ExcelApp.workbooks.add;
ExcelApp.workbooks[1].worksheets[1].Name:='客户选择';
Sheet:=ExcelApp.workbooks[1].worksheets[1];
rowcnt:=1;
Sheet.Cells[rowcnt,1] :='客户代码';
Sheet.Cells[rowcnt,2] :='客户名称';
dxSelect.First;
while not dxSelect.Eof do
begin
inc(rowcnt);
Sheet.Cells[rowcnt,1]:=''''+dxSelect.FieldByName('KHDM').AsString;
Sheet.Cells[rowcnt,2]:=''''+dxSelect.FieldByName('KHMC').AsString;
dxSelect.Next;
end;
finally
dxSelect.GotoBookmark (bk);
end;
end;
var
ExcelApp,Sheet:Olevariant;
rowcnt:integer;
bk:TBookMark;
begin
try
bk:=dxSelect.GetBookmark;
if dxSelect.IsEmpty then Exit;
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.visible:=true;
ExcelApp.workbooks.add;
ExcelApp.workbooks[1].worksheets[1].Name:='客户选择';
Sheet:=ExcelApp.workbooks[1].worksheets[1];
rowcnt:=1;
Sheet.Cells[rowcnt,1] :='客户代码';
Sheet.Cells[rowcnt,2] :='客户名称';
dxSelect.First;
while not dxSelect.Eof do
begin
inc(rowcnt);
Sheet.Cells[rowcnt,1]:=''''+dxSelect.FieldByName('KHDM').AsString;
Sheet.Cells[rowcnt,2]:=''''+dxSelect.FieldByName('KHMC').AsString;
dxSelect.Next;
end;
finally
dxSelect.GotoBookmark (bk);
end;
end;