delphi导出到excel,默认路径和excel名称.该怎么处理
答案:2 悬赏:60 手机版
解决时间 2021-02-21 01:18
- 提问者网友:别再叽里呱啦
- 2021-02-20 16:31
delphi导出到excel,默认路径和excel名称.该怎么处理
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-02-20 16:59
使用savedialog 属性Initialdir Filename
全部回答
- 1楼网友:时间的尘埃
- 2021-02-20 18:35
首先在uses处加上comobj procedure tform1.button1click(sender: tobject); var h,k:integer; excelid: olevariant; s: string; begin try excelid := createoleobject('excel.application'); except application.messagebox('excel没有安装!', '提示信息', mb_ok+mb_iconasterisk+mb_defbutton1+mb_applmodal); exit; end; try adoquery1.close; adoquery1.sql.clear; adoquery1.sql.add('select * from jj_department'); adoquery1.open; k:=adoquery1.recordcount; excelid.visible := true; excelid.workbooks.add; excelid.worksheets[1].range['a1:c1'].merge(true); excelid.worksheets[1].cells[1,1].value :='部门编码表' ; excelid.worksheets[1].range['a1:a1'].horizontalalignment := $ffffeff4; excelid.worksheets[1].range['a1:a1'].verticalalignment := $ffffeff4; excelid.worksheets[1].cells[2,1].value := '组别编号'; excelid.worksheets[1].cells[2,2].value := '公司编号'; excelid.worksheets[1].cells[2,3].value := '组别名称'; excelid.worksheets[1].range['a1:c1'].font.name := '宋体'; excelid.worksheets[1].range['a1:c1'].font.size := 9; excelid.worksheets[1].range['a1:c2'].font.bold:=true; excelid.worksheets[1].range['a2:c2'].font.size := 9; excelid.worksheets[1].range['a2:c2'].horizontalalignment := $ffffeff4; excelid.worksheets[1].range['a2:c2'].verticalalignment := $ffffeff4; h:=3; adoquery1.first; while not adoquery1.eof do begin excelid.worksheets[1].cells[h,1].value := adoquery1.fieldbyname('fdept_id').asstring; excelid.worksheets[1].cells[h,2].value := adoquery1.fieldbyname('ffdept_id').asstring; excelid.worksheets[1].cells[h,3].value := adoquery1.fieldbyname('fdept_name').asstring; inc(h); adoquery1.next; end; s := 'a2:f'+ inttostr(k+2); excelid.worksheets[1].range[s].font.name := '宋体'; excelid.worksheets[1].range[s].font.size := 9; excelid.worksheets[1].range[s].borders.linestyle := 1; excelid.quit; except application.messagebox('导入数据出错!请检查文件的格式是否正确!', '提示信息', mb_ok+mb_iconasterisk+mb_defbutton1+mb_applmodal); end; messagebox(getactivewindow(), 'excel数据导出成功!', '提示信息', mb_ok +mb_iconwarning); end;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯