把DBF文件导出成EXCEL文件

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

&&把DBF文件导出成EXCEL文件,导出后不用再调整格式,可直接打印。&&使用方法:先打开DBF数据库,再运行此程序即可PARAMETERSthefilename,theheader&&导出后保存的文件名和EXECL表格表头curprint=ALIAS()IFEMPTY(theheader)theheader=curprintendif**PUBLICdbfarray(30,15)ncount=AFIELDS(dbfarray)****以下代码检查每个字段的最长字符的长度,并将此长度数据保存到dbfarray(i,3)中.LOCALfld1,len1FORi=1TOncountfld1=ALLTRIM(dbfarray(i,1))len1=LEN(fld1)DOcasecasedbfarray(i,2)=CORdbfarray(i,2)=VSELECTMAX(LEN(ALLTRIM(&fld1)))asmaxlenFROM&curprintINTOCURSORthelendbfarray(i,3)=IIF(len1thelen.maxlen,len1,thelen.maxlen-1)casedbfarray(i,2)=Ddbfarray(i,3)=IIF(len1dbfarray(i,3)+DBFarray(i,4)+1,len1,DBFarray(i,3)+dbfarray(i,4)+1)CASEdbfarray(i,2)=Tdbfarray(i,3)=IIF(len115,len1,15)otherwisedbfarray(i,3)=IIF(len1dbfarray(i,3)+DBFarray(i,4),len1,DBFarray(i,3)+dbfarray(i,4))endcasedbfarray(i,3)=IIF(dbfarray(i,3)=5,dbfarray(i,3)+1,dbfarray(i,3))ENDFORGOtopWAITWINDOW正在导出数据.......ATMROW(),MCOL()nowait**以下设置EXCEL表格头oex1=CREATEOBJECT(excel.application)IfType(oex1)OMESSAGEBOX(创建EXCEL文件出错,当前系统可能没有安装MicrosoftEXCEL或者EXCEL运行出错.,0+16,提示)RETURNendifoex1.workbooks.addoex1.worksheets(sheet1).activateoex1.activesheet.pagesetup.printtitlerows=$1:$2oex1.activesheet.pagesetup.papersize=9oex1.activesheet.pagesetup.orientation=1oex1.activesheet.pagesetup.centerfooter=第&P页共&N页oex1.activesheet.pagesetup.headermargin=2/0.035oex1.activesheet.pagesetup.footermargin=2/0.035oex1.activesheet.pagesetup.zoom=100oex1.cells(1,1).value=theheaderoex1.cells(1,1).font.name=黑体oex1.cells(1,1).font.size=14oex1.cells(1,1).horizontalalignment=2oex1.range(retuabc(1)+1:+retuabc(ncount)+1).merge**oex1.visible=.t.****以下循环生成表格头FORi=1TOncountoex1.activesheet.columns(i).font.size=10IFdbfarray(i,3)=60oex1.activesheet.columns(i).columnwidth=dbfarray(i,3)ELSEoex1.activesheet.columns(i).columnwidth=60&&&如果字段宽度超过60字符,则设置为最宽为60,单元格为自动换行.oex1.activesheet.columns(i).WrapText=.t.&&&设置此列单元格为自动换行.endifIFdbfarray(i,2)=Coex1.activesheet.columns(i).numberformatlocal=@endifIF.f.IFINDBC(ctable,table)&&*判断表是否包含在当前数据库中ccaption=DBGETPROP(ctable+.+dbfarray(i,1),field,caption)IFNOTEMPTY(ccaption)&&判断在数据字典中是否设置了字段标题oex1.cells(2,i).value=ccaption&&使用数据字典中的列标题ELSEoex1.cells(2,i).value=dbfarray(i,1)&&未设置则直接用字段名称为列标题ENDIFENDIFENDIFoex1.cells(2,i).value=dbfarray(i,1)&&如非数据库,则直接用字段名称为列标题oex1.cells(2,i).horizontalalignment=3&&对齐方式为水平居中ENDFOR***以下生成表内容**PUBLICcfield,thefieldsSELECT&curprintnrow=3LOCALthecount,thecount1thecount=RECCOUNT()thecount1=ALLTRIM(STR(thecount))GOtopSCANWAIT共有+thecount1+条记录,正在导出第+ALLTRIM(STR(nrow-2))+条记录.WINDOWATMROW(),MCOL()nowait**oex1.visible=.t.LOCALcfieldFORncolumn=1toncountcfield=dbfarray(ncolumn,1)LOCALthefieldsthefields=&cfieldIFdbfarray(ncolumn,2)=Cthefields=ALLTRIM(thefields)ENDIFIFdbfarray(ncolumn,2)=Vthefields='+ALLTRIM(thefields)ENDIFIFdbfarray(ncolumn,2)=DAND(thefields={^1900-01-01}orISNULL(thefields))thefields=ENDIFIFdbfarray(ncolumn,2)=Lthefields=IIF(thefields,是,否)ENDIFIFEMPTY(thefields)thefields=ENDIFoex1.cells(nrow,ncolumn).value=thefieldsENDFORnrow=nrow+1ENDSCANoex1.range(A2:+retuabc(ncount)+ALLTRIM(STR(nrow-1))).borders.linestyle=1&&细线边框oex1.range(A2:+retuabc(ncount)+ALLTRIM(STR(nrow-1))).borders.weight=2&&粗细线oex1.cells(nrow+1,1).value=报表日期oex1.cells(nrow+1,2).value=STR(YEAR(DATE()),4)+年+STR(month(DATE()),2)+月+STR(day(DATE()),2)+日oex1.cells(nrow+1,3).value=报表单位oex1.cells(nrow+1,4).value=GSNAMEWAITclearIFUSED(thelen)USEINthelenENDIFoex1.activeworkbook.saveas(thefilename)oex1.visible=.t.PROCEDUREretuabcPARAMETERSnNumbernnumber1=CEILING(nnumber/26)+63IFnnumber164cabcd=CHR(nnumber1)ELSEcabcd=ENDIFnasc=MOD(nnumber,26)IFnasc=0nasc=26ENDIFcabc=cabcd+CHR(64+nasc)RETURNcabcENDPROC

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功