您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

导出EXCEL/FOXPRO/PRODOX格式表

2024/10/23 10:35:55发布34次查看
一般是在access或是sqlserver中查寻,或是汇总,然后生成一个‘记录集’可以显示在grid里,也可以将这个记录集 导出 到磁盘中。 下面可以 导出 xls,dbf,db,mdb(表),这些功能是由isam数据库接口实现,为了 导出 各种版本的文件,我在ms网站下载了最新的jet4
一般是在access或是sqlserver中查寻,或是汇总,然后生成一个‘记录集’可以显示在grid里,也可以将这个记录集导出到磁盘中。下面可以导出xls,dbf,db,mdb(表),这些功能是由isam数据库接口实现,为了导出各种版本的文件,我在ms网站下载了最新的jet4和mdac6。前者到用于桌面数据库如access,foxpro的组件,后者是实现新版本ado组件。分别在:
http://download.microsoft.com/download/access2000/sp/4.0/nt5/en-us/jet40sp5_w2k.exe
http://download.microsoft.com/download/dasdk/install/2.60.6526.3/win98me/cn/mdac_typ.exe
这些是标准的sql导出语句:
select*into[office/9.shtml'target='_blank'class='article'>excel8.0;database=导出目录].导出表名from表
select*into[foxpro2.6;database=导出目录].导出表名from表
select*into[foxpro2.5;database=同上].导出表名from表
select*into[dbaseiii;database=同上].导出表名from表
select*into[paradox4.x;database=同上].导出表名from表
select*into[;database=c:\temp\xxx.mdb].导出表名from表
下面程序为实现用户自定议文件名用变量代替一部分。
http://go.163.com/~chunpeng/project/export.jpg
http://go.163.com/~chunpeng/project/export.zip点这里下载原程序文件。
'请先引用adodb类库。
dimexport_str,mdbtableasstring
dimrsexportasnewadodb.recordset
dimconnasnewadodb.connection
privatesubclose_cmd_click()
unloadme
endsub
privatesubexport_cmd_click()
dimmypath,mystrasstring,myposasinteger
'******************处理选择的各种表的导出
withdialog1
ifmyoption(2).valuethen
.filterindex=1
.showsave
mystr=strreverse(.filename)'串取反
mypos=instr(mystr,\)'在反字符串中,找从左开始第一个\的位置
onerrorgotomyerror'防filename为空,mid出错
mypath=strreverse(mid(mystr,mypos))'取目录部分,并还原.
mystr=strreverse(left(mystr,mypos-1))'取文件名
export_str=select*into[dbaseiii;database=&mypath&].&mystr&fromcustomers
.defaultext=*.dbf
elseifmyoption(3).valuethen
mdbtable=inputbox(请给导出到mdb文件的表确定表名)
.filterindex=2
.showsave
export_str=select*into[;database=&.filename&].&mdbtable&fromcustomers
.defaultext=*.mdb 
elseifmyoption(4).valuethen
.filterindex=3
.showsave
export_str=select*into[excel8.0;database=&.filename&].customersfromcustomers
.defaultext=*.xls
elseifmyoption(5).valuethen
.filterindex=4
.showsave
mystr=strreverse(.filename)'串取反
mypos=instr(mystr,\)'在反字符串中,找从左开始第一个\的位置
onerrorgotomyerror'防filename为空,mid出错
mypath=strreverse(mid(mystr,mypos))'取目录部分,并还原.
mystr=strreverse(left(mystr,mypos-1))'取文件名
export_str=select*into[paradox4.x;database=&mypath&].&mystr&fromcustomers
.defaultext=*.db
endif
endwith
'*****生成文件
debug.printexport_str
ifrsexport.state=1then
rsexport.close
endif 
ifdir(dialog1.filename)then
onerrorgotomyerror'防用户没选文件
ifdialog1.filterindex2then
kill(dialog1.filename)
endif
rsexport.openexport_str,conn,adopenstatic,adlockoptimistic
else
rsexport.openexport_str,conn,adopenstatic,adlockoptimistic
endif
myerror:
exitsub
endsub
privatesubform_load()
'联接数据库并打开记录集
conn.cursorlocation=aduseserver
conn.openprovider=microsoft.jet.oledb.4.0;datasource= app.path \nwind.mdb;
rsexport.openselect*fromcustomers,conn,adopenstatic,adlockoptimistic
setgrid1.datasource=rsexport
'初始化对话筐
withdialog1
.filter=foxbase/foxpro(*.dbf) *.dbf access8.0(*.mdb) *.mdb excel8.0(*.xls) *.xls paradox4.x(*.db) *.db
.dialogtitle=导出文件为
.cancelerror=false
endwith
endsub
->
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product