版主帮我看一下这段过程代码:
***********************************************************************
*
将DBF数据导出到指定EXCEL文件中
*
***********************************************************************
PROCEDURE EXPORTTOXLS
DIMENSION
PidArr(5000)
LOCAL oExcel,DrtPhoto,RecordNum,nDataTotal1,nDataTotal2,mm,nn
SET DATE YMD
STORE "" TO PidArr
frmEi.oleStatusBar.Visible = .F.
frmEi.lblProgressBar.Caption = "正在导出数据,请稍候..."
frmEi.shpProgressBar1.Left = LEN(frmEi.lblProgressBar.Caption)*120*_rateV/22
frmEi.shpProgressBar2.Left = LEN(frmEi.lblProgressBar.Caption)*120*_rateV/22
frmEi.lblProgressBar.Visible = .T.
frmEi.shpProgressBar1.Visible = .T.
frmEi.shpProgressBar2.Visible = .T.
oExcel=CREATEOBJECT('Excel.Application')
IF NOT TYPE("oExcel") = "O"
=MESSAGEBOX("Excel对象创建失败,程序将中止!", 16, "错误")
RETURN
ENDIF
cExcelFile=GETFILE("MicroSoft Office Excel 工作薄:xls")
IF .NOT. SUBSTR(SUBSTR(cExcelFile,RAT("\",cExcelFile)+1),1,AT(".",SUBSTR(cExcelFile,RAT("\",cExcelFile)+1))-1)=="员工基本信息采集表—生成数据库"
=MESSAGEBOX("请打开“员工基本信息采集表—生成数据库!”工作薄",64,"系统提示")
RETURN
ENDIF
oExcel.Workbooks.Open("&cExcelFile")
oExcel.Visible=.F.
oExcel.Worksheets("生成数据库").Activate
oExcel.ActiveSheet.UnProtect('711205')
oExcel.Application.ScreenUpdating = .F.
FOR I=4 TO 5000
IF EMPTY(oExcel.Worksheets("生成数据库").Cells(I,1).Value)
nDataTotal1=I
EXIT
ENDIF
PidArr(I-3)=oExcel.Worksheets("生成数据库").Cells(I,3).Value
ENDFOR
oExcel.Worksheets("员工照片").Activate
oExcel.ActiveSheet.UnProtect('711205')
FOR I=2 TO 5000
IF EMPTY(oExcel.Worksheets("员工照片").Cells(I,1).Value)
nDataTotal2=I
EXIT
ENDIF
ENDFOR
nFldCount =AFIELDS(aFldList,"Ei")
J=0
P=0
SCAN FOR &ExportCondition
J=J+1
frmEi.shpProgressBar1.Width = J*200*_rateV/(ExportReccount+nFldCount-1)
SCATTER MEMVAR MEMO
PersonnelName=TRIM(Ei.姓名)
PersonnelIdcard=TRIM(Ei.身份证号)
IF ASCAN(PidArr,PersonnelIdcard)<>0
IF MESSAGEBOX("身份证号为“"+PersonnelIdcard+"”("+PersonnelName+")的员工信息已存在,"+CHR(10)+CHR(10)+"现在更新吗?",36,"系统询问")=6
P=P+1
mm=ASCAN(PidArr,PersonnelIdcard)+3
nn=ASCAN(PidArr,PersonnelIdcard)+1
ELSE
LOOP
ENDIF
ELSE
P=P+1
mm=nDataTotal1
nn=nDataTotal2
nDataTotal1=nDataTotal1+1
nDataTotal2=nDataTotal2+1
ENDIF
oExcel.Worksheets("员工照片").Activate
RecordNum=oExcel.ActiveSheet.Cells(nn-1,1).Value
IF TYPE("RecordNum")="N"
oExcel.ActiveSheet.Cells(nn,1).Value=RecordNum+1
ELSE
oExcel.ActiveSheet.Cells(nn,1).Value=1
ENDIF
dValue=TRIM(Ei.姓名)
IF NOT ISNULL(dValue)
oExcel.ActiveSheet.Cells(nn,2).Value=dValue
ENDIF
dValue=TRIM(Ei.身份证号)
IF NOT ISNULL(dValue)
oExcel.ActiveSheet.Cells(nn,3).Value=dValue
ENDIF
IF oExcel.ActiveSheet.Rows(nn).RowHeight=108
FOR EACH DrtPhoto IN oExcel.ActiveSheet.DrawingObjects
IF !ISNULL(oExcel.Intersect(DrtPhoto.TopLeftCell,oExcel.ActiveSheet.Cells(nn, 4)))
DrtPhoto.Delete
ENDIF
ENDFOR
ENDIF
IF !EMPTY(Ei.照片)
COPY TO temp FIELDS Ei.照片 NEXT 1
handlein=FOPEN("temp.fpt")
lcFile=DefaultPath+"test.bmp"
handleout=FCREATE(lcFile)
gnEnd=FSEEK(handlein,0,2)
gnTop=FSEEK(handlein,0)
str1=FREAD(handlein,gnEnd)
str2=RIGHT(str1,LEN(str1)-599)
n=FWRITE(handleout,str2)
=FCLOSE(handlein)
=FCLOSE(handleout)
ERASE temp.*
oExcel.ActiveSheet.Cells(nn,4).Select
IF FILE("&lcFile")
oExcel.Selection.RowHeight=108
oExcel.ActiveSheet.Pictures.Insert(lcFile).Select
oExcel.Selection.ShapeRange.LockAspectRatio=.F.
oExcel.Selection.ShapeRange.Height=107.25
oExcel.Selection.ShapeRange.Width=82.5
oExcel.Selection.ShapeRange.Top=oExcel.ActiveSheet.Cells(nn,4).Top + 0.75
oExcel.Selection.ShapeRange.Left=oExcel.ActiveSheet.Cells(nn,4).Left + 0.75
oExcel.Selection.Placement = 2
ERASE &lcFile
ELSE
oExcel.ActiveSheet.Cells(nn,4).RowHeight=14.25
ENDIF
ELSE
oExcel.ActiveSheet.Cells(nn,4).RowHeight=14.25
ENDIF
oExcel.ActiveSheet.Cells(nn,1).Select
oExcel.Worksheets("生成数据库").Activate
RecordNum=oExcel.ActiveSheet.Cells(mm-1,1).Value
IF TYPE("RecordNum")="N"
oExcel.ActiveSheet.Cells(mm,1).Value=RecordNum+1
ELSE
oExcel.ActiveSheet.Cells(mm,1).Value=1
ENDIF
FOR J=2 TO nFldCount-14
mmm=ALLTRIM(STR(mm))
oExcel.ActiveSheet.Range("A"+mmm+":BU"+mmm).VerticalAlignment =1
dValue = .NULL.
IF AT(aFldList[J,2],"CDLMNFIBYT")=0
LOOP
ENDIF
cFieldName=aFldList[J,1]
dValue = EVALUATE(cFieldName)
DO CASE
CASE aFldList[J,2]="C"
dValue=TRIM(dValue)
CASE aFldList[J,2]="D"
dValue=IIF(!EMPTY(dValue),DTOC(dValue),"")
CASE aFldList[J,2]="T"
dValue=IIF(!EMPTY(dValue),TTOC(dValue),"")
CASE INLIST(aFldList[J,2],"N","F","I","B","Y")
CASE aFldList[J,2]="L"
IF dValue
dValue=IIF(J=30 .OR. J=34,"是","有")
ELSE
dValue=IIF(J=30 .OR. J=34,"否","无")
ENDIF
IF J=34 .AND. dValue="否"
oExcel.Worksheets("生成数据库").Cells(mm,J-1).Value="无"
ENDIF
CASE aFldList[J,2]="M"
OTHERWISE
dValue=.NULL.
ENDCASE
IF VARTYPE(dValue)="C" .AND. EMPTY(dValue)
LOOP
ENDIF
IF NOT ISNULL(dValue)
DO CASE
CASE J<30
oExcel.Worksheets("生成数据库").Cells(mm,J).Value=dValue
CASE J>30 .AND.J<34
oExcel.Worksheets("生成数据库").Cells(mm,J-1).Value=dValue
CASE J>34
oExcel.Worksheets("生成数据库").Cells(mm,J-2).Value=dValue
ENDCASE
ENDIF
ENDFOR
oExcel.ActiveSheet.Cells(mm,1).Select
ENDSCAN
cChrStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR J=2 TO nFldCount-1
frmEi.shpProgressBar1.Width = (ExportReccount+J)*200*_rateV/(ExportReccount+nFldCount-1)
IF aFldList[J, 2]="M"
cColumn=SUBSTR(cChrStr,INT((J-1)/26),1)+SUBSTR(cChrStr,IIF(MOD(J,26)=0,26,MOD(J, 26)),1)
oExcel.Worksheets("生成数据库").Columns(cColumn+":"+cColumn).WrapText=.T.
ENDIF
ENDFOR
oExcel.Worksheets("员工照片").Activate
oExcel.ActiveSheet.Protect('711205',.T.,.T.,.T.)
oExcel.Worksheets("生成数据库").Activate
oExcel.ActiveSheet.Protect('711205',.T.,.T.,.T.)
oExcel.Application.ScreenUpdating = .T.
oExcel.ActiveWorkbook.Save
=MESSAGEBOX("成功导出"+ALLTRIM(STR(P))+"名员工的数据记录!", 64, "系统提示")
oExcel.Visible=.T.
frmEi.lblProgressBar.Caption = ""
frmEi.shpProgressBar1.Width = 0
frmEi.oleStatusBar.Visible = .T.
frmEi.lblProgressBar.Visible = .F.
frmEi.shpProgressBar1.Visible = .F.
frmEi.shpProgressBar2.Visible = .F.
oExcel=.NULL.
ENDPROC
***********************************************************************
这段代码在6.0中一点问题也没有,可在9.0中运行时,首先说
nDataTotal1=nDataTotal1+1
这句是数据类型不匹配
我在前面加一一句:
STORE 0 TO RecordNum,nDataTotal1,nDataTotal2,mm,nn
又说
RecordNum=oExcel.ActiveSheet.Cells(nn-1,1).Value
这句Cells不是一个对象,搞得我很晕