利用剪切板快速导入Excel
var
y :integer;
tsList :TStringList;
s :string;
aSheet :Variant;
Q_excel :TQuery ;
Clipboard1 : TClipboard;
begin
try
Q_excel := TQuery.Create(nil);
with Q_excel do
begin
databasename := '你的数据库别名';
sql.clear;
sql.Add ('select * from 表名');
open;
first;
end;
//=================================
tsList:=TStringList.Create;
while not Q_excel.Eof do
begin
s := '';
for y:=0 to Q_excel.FieldCount-1 do
begin
s:=s+Q_excel.Fields[y].AsString+#9;
Application.ProcessMessages;
end;
tsList.Add(s);
Q_excel.next;
end;
finally
Q_excel.Close;
Q_excel.Destroy ;
end;
//==剪切板== 需要uses : Clipbrd
try
if Clipboard1 = nil then
begin
Clipboard1 := TClipboard.create;
end;
Clipboard1.AsText:=tsList.Text;
finally
Clipboard1.Destroy ;
Clipboard1 := nil ;
end;
//==剪切板==
//==倒入excel,用的是server中的控件
try
try
ExcelApplication1.connect;
except
showMessage('请安装Excel!') ;
exit;
end;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
ExcelApplication1.Workbooks.Add(Null,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
//==
ExcelWorksheet1.Paste ;
//==
finally
ExcelApplication1.Disconnect;
end;
end;
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论