如何将access里头的查询导出成excel
最好有个界面让选择access文件.然后存文件也有个选择的路径的.谢谢先
最好有个界面让选择access文件.然后存文件也有个选择的路径的.谢谢先
解决方案 »
- 从注册表读取出来的16进制转换成日期时间的算法请教!
- 还是赋值问题,系统报错说
- SQL记录定位,并在Form间传递的问题
- 请问:C/S结构,在程序实现数据导出功能,该如何保持数据的完整型?要不要对连接或者数据集进行专门的设置?谢谢大家,不好意思,分有点少.
- 在线等待,急用!!!
- 关于DeleteFile函数的问题?急(在线等待)
- 请问MVC(MODEL VIEW CONTROLS)是什么指的意思??
- 数据长度和delphi
- 为什么动态生成的webbrowser不能 拷贝,剪切,粘贴?
- 我用一个QUERY,想修改指定的一个记录,但不 知为什么却变成了加一个新记录,且新记录的字段的值是我要修改的字段的值,
- 见鬼了!!!----------窗体大小不受控了???
- delphi的md4加密怎么实现?
那么,1 你打算导入到哪2 从STRINGGRID导出EXCEL 偶有现成语句,但前提是1是什么
比如里头有两个表t1 t2我现在想导出
select t1.* from t1,t2 where t1.id=t2.id想导出这个查询的结果至一个excel文件.
var
strCurrentDir: string;
strfilename: string;
i, j: integer;
eclApp, WorkBook: variant;
begin
strCurrentDir := GetCurrentDir();
try
eclApp := CreateOleObject('Excel.Application');
WorkBook := CreateOleObject('Excel.Sheet');
except
Application.MessageBox('你的机器未装MS EXCEL.', '操作提示-警告', MB_ICONWARNING);
exit;
end; try
if savedialog1.Execute then
begin
strfilename := savedialog1.FileName;
end
else
exit; ProgressBar1.Visible := true;
ProgressBar1.Max := sg_List.RowCount;
lbl_Message.Font.Color := clgreen;
lbl_Message.Caption := '开始导出.';
workBook := eclApp.workBooks.add;
eclApp.cells[1, 13] := 'title';
for i := 0 to sg_List.RowCount - 1 do
begin
for j := 1 to sg_List.ColCount - 1 do
begin
eclApp.cells[i + 3, j] := sg_List.Cells[j, i];
end;
self.Repaint;
end;
workBook.saveas(strfilename);
workBook.close;
eclApp.quit;
eclApp := unassigned;
except
Application.MessageBox('不能操作该文件.可能是该文件已被其他程序打开,或文件错误.', '操作提示-警告', MB_ICONWARNING);
workBook.close;
eclApp.quit;
eclApp := unassigned;
end;
SetCurrentDir(strCurrentDir);
end;
这个是从TSTRINGGRID导出到EXCEL的代码,你可以自己改
ProgressBar1.Max := sg_List.RowCount;
lbl_Message.Font.Color := clgreen;
lbl_Message.Caption := '开始导出.';无视这段话
i:integer;
reccount:string;
begin
if not fileexists(edt_file.Text) then
begin
application.MessageBox('文件不存在,请选择要导入的文件!','提示',mb_ok+mb_iconinformation);
exit;
end;
dm_main.adocnmain.BeginTrans;
tmpsource:=tadoquery.Create(nil);
tmpsource.ConnectionString:='provider=microsoft.jet.oledb.4.0;data source='+edt_file.Text+
';extended properties =excel 8.0;persist security info=false';
tmpdest:=tadoquery.Create(nil);
tmpdest.ConnectionString:=dm.adocnmain.ConnectionString;
gauge1.MaxValue :=tmpsource.RecordCount;
reccount:=inttostr(tmpsource.RecordCount);
try
for i:=0 to tmpsource.RecordCount-1 do
begin
with tmpdest do
begin
sql.Clear;
sql.Add('insert into T_stu (stuid,stuname,stusex,sturace,stugrade,stuclass,stubg,workdate,borndate,stuaddress,stumail,logpsw)');
sql.Add('values (:v1,:v2,:v3,:v4,:v5,:v6,:v7,:v8,:v9,:v10,:v11,:v12)');
parameters.ParamByName('v1').Value :=tmpsource.FieldByName('StuID').AsString;
parameters.ParamByName('v2').Value:=tmpsource.FieldByName('stuname').AsString;
parameters.ParamByName('v3').Value:=tmpsource.FieldByName('stusex').AsString;
parameters.ParamByName('v4').Value:=tmpsource.FieldByName('sturace').AsString;
parameters.ParamByName('v5').Value:=tmpsource.FieldByName('stugrade').AsString;
parameters.ParamByName('v6').Value:=tmpsource.FieldByName('stuclass').AsString;
parameters.ParamByName('v7').Value:=tmpsource.FieldByName('stubg').AsString;
parameters.ParamByName('v8').Value:=tmpsource.FieldByName('workdate').AsDateTime;
parameters.ParamByName('v9').Value:=tmpsource.FieldByName('borndate').AsDateTime;
parameters.ParamByName('v10').Value:=tmpsource.FieldByName('stuaddress').AsString;
parameters.ParamByName('v11').Value:=tmpsource.FieldByName('stumail').AsString;
parameters.ParamByName('v12').Value:=IniPsw;
execsql;
end;
tmpsource.Next;
gauge1.AddProgress(gauge1.MaxValue div tmpsource.RecordCount);
end;
dm.adocnmain.CommitTrans;
application.MessageBox('数据导入成功!','提示',mb_ok+mb_iconinformation);
close;
except
on e:exception do
begin
dm.adocnmain.RollbackTrans;
application.MessageBox('数据导入失败!''警告',mb_ok+mb_iconwarning);
end;
end;
finally
tmpsource.Free;
tmpdest.Free;
end;
CreateOleObject 这个报错了,不晓得是什么,是不是前面得引用什么单元?
sg_List 这个是用了ListBox组件吗
其实就是把SG_LIST中的CELLS[x,y]写EXCEL里对应单元格