set talk off
set Default to &mypath\导出数据
oExcelSheet = GETOBJECT("","Excel.Sheet") && 产生Excel对象
IF NOT TYPE("oExcelSheet") = "O"
=MESSAGEBOX("Excel对象创建失败,程序将中止!", 16, "Error")
RETURN
ENDIF
outfilename=putfile('输出结果','&bm','xls')
oExcelApp = oExcelSheet.Application
oExcelApp.Workbooks.Add()
oExcelApp.ActiveWindow.WindowState=2
oSheet = oExcelApp.ActiveSheet
oSheet.visible=.t.
if used("cx")
sele cx
else
use &mypath/cx
endi
nFldCount = AFIELDS(aFldList,"cx")
FOR i = 1 TO nFldCount
oSheet.Cells(3,i).Value = aFldList[i, 1]
cChrStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
cColumn = SUBSTR(cChrStr, INT((i-1)/26), 1) + SUBSTR(cChrStr, IIF(MOD(i, 26)= 0, 26, MOD(i, 26)) , 1)
*oSheet.Columns("&cColumn").Select
if aFldList[i, 1]="N"
oSheet.Columns(cColumn + ":" + cColumn).NumberFormatLocal="0.00" &&设置为字符型内容
ELSE
oSheet.Columns(cColumn + ":" + cColumn).NumberFormatLocal="@" &&设置为字符型内容
endi
oSheet.Columns(cColumn + ":" + cColumn).ShrinkToFit =.t.
ENDFOR
cRecc = STR(RECCOUNT("cx"))
SCAN
thisform.caption="讷河市社保局友情提供
正在处理第"+allt(str(recno()))+'条.总数:'+allt(cRecc)
FOR i = 1 TO nFldCount
vValue = .NULL.
IF AT(aFldList[i, 2], "CDLMNFIBYT") = 0
LOOP
ENDIF
cFldName = aFldList[i, 1]
vValue = EVALUATE(cFldName)
DO CASE
CASE aFldList[i, 2] = "C" && 字符/字符串
vValue = TRIM(vValue)
CASE aFldList[i, 2] = "D" && 日期
vValue = DTOC(vValue)
CASE aFldList[i, 2] = "T" && 日期时间
vValue = TTOC(vValue)
CASE INLIST(aFldList[i, 2], "N", "F", "I", "B", "Y") && 数值
CASE aFldList[i, 2] = "L" && 逻辑
CASE aFldList[i, 2] = "M" && 备注型
OTHERWISE
vValue = .NULL.
ENDCASE
IF VARTYPE(vValue) = "C" AND EMPTY(vValue)
LOOP
ENDIF
IF NOT ISNULL(vValue)
oSheet.Cells(RECNO("cx")+3, i).Value = vValue
ENDIF
ENDFOR
ENDSCAN
cChrStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR i = 1 TO nFldCount
cColumn = SUBSTR(cChrStr, INT((i-1)/26), 1) + SUBSTR(cChrStr, IIF(MOD(i, 26)= 0, 26, MOD(i, 26)) , 1)
oSheet.Columns(cColumn + ":" + cColumn).ColumnWidth = 12
IF aFldList[i, 2] = "M"
oSheet.Columns(cColumn + ":" + cColumn).WrapText = .F.
ENDIF
ENDFOR
oExcelApp.ActiveWorkbook.SaveAs(outfilename)
oExcelApp.ActiveWorkbook.Close(.F.)
oExcelApp.ActiveWorkbook.Close(.F.)
oExcelApp.Quit
oExcelSheet = .NULL.
oExcelApp = .NULL.
*WAIT CLEAR
thisform.caption="讷河市社保局友情提供"
=MESSAGEBOX("导出完毕!总共导出:"+allt(cRecc)+"人。
",64, "OK")