VFP导入EXCEL探讨
程序代码:
SET DATE YMD SET CENTURY ON CDBFFILE = GETFILE("dbf") IF EMPTY(CDBFFILE) RETURN ENDIF SELECT * FROM JUSTSTEM(CDBFFILE) INTO CURSOR FOXTABLE JLS=TRANSFORM(RECCOUNT()+1) CEXCELFILE = PUTFILE("保存为(&N):",JUSTSTEM(CDBFFILE)+".xls","xls") IF EMPTY(CEXCELFILE) RETURN ENDIF SELECT FOXTABLE OEXCELSHEET = GETOBJECT("","Excel.Sheet") IF NOT TYPE("oExcelSheet") = "O" =MESSAGEBOX("Excel对象创建失败,程序将中止!", 16, "Error") RETURN ENDIF OEXCEL = CREATEOBJECT("excel.application") WITH OEXCEL .WORKBOOKS.ADD .SHEETS("Sheet1").SELECT .SHEETS("Sheet1").NAME = "sample" .VISIBLE=.F. .DISPLAYALERTS = .F. .CELLS.SELECT WITH .SELECTION.FONT .NAME = "宋体" .SIZE = 10 ENDWITH ENDWITH OEXCEL.ACTIVESHEET.ROWS(1).ROWHEIGHT=24 && 设置第表头行行高 OEXCEL.ACTIVESHEET.ROWS('2:&JLS').ROWHEIGHT=20 && 设置第2行到最后高度行高 C_1="ABCDEFGHIJKLMNOPQRSTUVWXYZ" DLINE_S="A1:"+CHR(ASC("A")+FCOUNT())+"1" OEXCEL.ActiveSheet.Range(DLINE_S).Borders(3).LineStyle=1 && 表格上边线 oexcel.ActiveSheet.Range(DLINE_S).Borders(3).Weight=3 && 指定边框线宽度 FOR I = 1 TO FCOUNT() OEXCEL.ACTIVESHEET.COLUMNS(I).COLUMNWIDTH=FSIZE(FIELD(I)) OEXCEL.CELLS(1,I).VALUE = FIELD(I) ENDFOR OEXCEL.SELECTION.HORIZONTALALIGNMENT=2 SCAN IF MOD(RECNO(),32)=1 DLINE_X="A"+TRANSFORM(RECNO())+":"+CHR(ASC("A")+FCOUNT())+TRANSFORM(RECNO()) OEXCEL.RANGE(DLINE_X).SELECT OEXCEL.SELECTION.BORDERS(-4107).LINESTYLE = 1 ENDIF FOR I=1 TO FCOUNT() MFIELD=FIELD(I) WAIT WINDOW TRANSFORM(RECNO()) + "/"+ TRANSFORM(RECCOUNT()) NOWAIT OEXCEL.CELLS(RECNO()+1,I).VALUE=&MFIELD ENDFOR IF MOD(RECNO(),32)=0 DLINE_X="A"+TRANSFORM(RECNO()+1)+":"+CHR(ASC("A")+FCOUNT())+TRANSFORM(RECNO()+1) OEXCEL.ActiveSheet.Range(DLINE_X).Borders(4).LineStyle=1 && 表格下边线 oexcel.ActiveSheet.Range(DLINE_X).Borders(4).Weight=3 && 指定边框线宽度 ENDIF IF RECNO()=RECCOUNT() DLINE_X="A"+TRANSFORM(RECCOUNT()+1)+":"+CHR(ASC("A")+FCOUNT())+TRANSFORM(RECCOUNT()+1) OEXCEL.ActiveSheet.Range(DLINE_X).Borders(4).LineStyle=9 && 表格下边线 ENDIF ENDSCAN OEXCEL.ActiveSheet.PageSetup.CenterHorizontally=.t. && 设置页面水平居中 oEXCEL.ActiveSheet.PageSetup.PrintTitleRows = "$1:$1" &&固定打印的顶端标题行(第1行) OEXCEL.ActiveSheet.PageSetup.CenterFooter="第"+"&P"+"页共"+"&N"+"页" &&页脚中间 OEXCEL.VISIBLE=.T. OEXCEL.ACTIVESHEET.PRINTPREVIEW OEXCEL.VISIBLE=.F. OEXCEL.ACTIVEWORKBOOK.SAVEAS(CEXCELFILE) OEXCEL.WORKBOOKS.CLOSE OEXCEL.QUIT RELEASE OEXCEL WAIT CLEAR =MESSAGEBOX("转换完毕!", 64, "OK")这段代码正常运行没有问题。如何完善上述代码,请大家发表下自己的看法。
关于表头字段下边线的设置问题,不知那位有更完善方法。
[ 本帖最后由 sdta 于 2012-5-19 13:26 编辑 ]