程序代码:
SET DATE YMD
SET CENTURY ON
CDBFFILE = GETFILE("dbf")
IF EMPTY(CDBFFILE)
RETURN
ENDIF
SELECT * FROM JUSTSTEM(CDBFFILE) INTO CURSOR FOXTABLE
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
DLINE_S = "A1:"+CHR(ASC("A")+FCOUNT()-1)+"1"
WITH OEXCEL
.CELLS(1, 1).VALUE = "江北大学物理系人员花名册"
.ACTIVESHEET.RANGE(DLINE_S).MERGE
.ACTIVESHEET.ROWS(1).ROWHEIGHT = 40
.RANGE(DLINE_S).SELECT
WITH .SELECTION
.FONT.NAME = "宋体"
.FONT.SIZE = 24
.FONT.BOLD = .T.
.HORIZONTALALIGNMENT = 3
.VERTICALALIGNMENT = 2
ENDWITH
ENDWITH
ROW = 2
JLS = TRANSFORM(RECCOUNT()+ROW)
RECROW = TRANSFORM(ROW+1)
ROW_BROWSE = 30
OEXCEL.ACTIVESHEET.ROWS(ROW).ROWHEIGHT = 24
OEXCEL.ACTIVESHEET.ROWS('&RECROW.:&JLS').ROWHEIGHT=20
DLINE_S = "A"+TRANSFORM(ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_S).BORDERS(3).LINESTYLE = 9
FOR I = 1 TO FCOUNT()
OEXCEL.ACTIVESHEET.COLUMNS(I).COLUMNWIDTH = IIF(LEN(FIELD(I)) > FSIZE(FIELD(I)),LEN(FIELD(I)),FSIZE(FIELD(I)))
OEXCEL.CELLS(ROW, I).VALUE = FIELD(I)
OEXCEL.ACTIVEWORKBOOK.SHEETS(1).CELLS(ROW, I).HORIZONTALALIGNMENT = 3
ENDFOR
OEXCEL.RANGE(DLINE_S).SELECT
OEXCEL.SELECTION.BORDERS(-4107).LINESTYLE = 1
SCAN
IF MOD(RECNO(),ROW_BROWSE) = 1
DLINE_X = "A"+TRANSFORM(RECNO())+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECNO())
ENDIF
FOR I = 1 TO FCOUNT("FOXTABLE")
MFIELD = FIELD(I)
WAIT WINDOW NOWAIT TRANSFORM(RECNO())+"/"+TRANSFORM(RECCOUNT())
OEXCEL.CELLS(RECNO()+ROW,I).VALUE=&MFIELD
ENDFOR
IF MOD(RECNO(),ROW_BROWSE) = 0
DLINE_X = "A"+TRANSFORM(RECNO()+ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECNO()+ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_X).BORDERS(4).LINESTYLE = 9
ENDIF
IF RECNO() = RECCOUNT()
DLINE_X = "A"+TRANSFORM(RECCOUNT()+ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECCOUNT()+ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_X).BORDERS(4).LINESTYLE = 9
ENDIF
ENDSCAN
OEXCEL.ACTIVESHEET.PAGESETUP.CENTERHORIZONTALLY = .T.
OEXCEL.ACTIVESHEET.PAGESETUP.PRINTTITLEROWS = "$1:$2"
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")
试试