dbf输出到excel中的指定单元格
现在有一个hz.dbf
h01 h02 h03 h04 dq
15 14 13 12 001
14 14 13 12 002
13 14 13 12 004
如果dq=001,将 h01,h02,h03,h04的是输出到指定单元格
如果dq=002,将 h01,h02,h03,h04的是输出到指定单元格
如果dq=003,将 h01,h02,h03,h04的是输出到指定单元格
如果dq=004,将 h01,h02,h03,h04的是输出到指定单元格
我的代码中
locate for dq= '001 '
if .not. eof()
oexl.ActiveSheet.Cells(7,2).value=hz.h01
oexl.ActiveSheet.Cells(7,3).value=hz.h02
oexl.ActiveSheet.Cells(7,4).value=hz.h03
oexl.ActiveSheet.Cells(7,5).value=hz.h04
endif
locate for dq= '002 '
if .not. eof()
oexl.ActiveSheet.Cells(8,2).value=hz.h01
oexl.ActiveSheet.Cells(8,3).value=hz.h02
oexl.ActiveSheet.Cells(8,4).value=hz.h03
oexl.ActiveSheet.Cells(8,5).value=hz.h04
endif
locate for dq= '003 '
if .not. eof()
oexl.ActiveSheet.Cells(9,2).value=hz.h01
oexl.ActiveSheet.Cells(9,3).value=hz.h02
oexl.ActiveSheet.Cells(9,4).value=hz.h03
oexl.ActiveSheet.Cells(9,5).value=hz.h04
endif
但是,excel中的第8行的数据和第7行的数据是一样的,是不是我代码里有问题?
[解决办法]
try:oexl=Createobject("excel.application")gft=Sys(5)+Curdir()+'hz.xls'oexl.workbooks.Open("&gft")oexl.worksheets("hz").ActivateSele hzLocate For Alltrim(dq)=='001'If Found() oexl.ActiveSheet.Cells(7,2).Value=hz.h01 oexl.ActiveSheet.Cells(7,3).Value=hz.h02 oexl.ActiveSheet.Cells(7,4).Value=hz.h03 oexl.ActiveSheet.Cells(7,5).Value=hz.h04Endif.Locate For Alltrim(dq)=='002'If Found() oexl.ActiveSheet.Cells(8,2).Value=hz.h01 oexl.ActiveSheet.Cells(8,3).Value=hz.h02 oexl.ActiveSheet.Cells(8,4).Value=hz.h03 oexl.ActiveSheet.Cells(8,5).Value=hz.h04EndifLocate For Alltrim(dq)=='003'If Found() oexl.ActiveSheet.Cells(9,2).Value=hz.h01 oexl.ActiveSheet.Cells(9,3).Value=hz.h02 oexl.ActiveSheet.Cells(9,4).Value=hz.h03 oexl.ActiveSheet.Cells(9,5).Value=hz.h04Endifoexl.worksheets("hz").Activatelj=Sys(5)+Curdir()+'汇总结果\'+'汇总.xls'oexl.activeworkbook.SaveAs("&lj")oexl.workbooks.Closeoexl.Visible=.T.oexl.QuitMessagebox("数据汇总成功!汇总文件位于汇总结果文件夹内!")
[解决办法]
OEXL=CREATEOBJECT("EXCEL.APPLICATION")GFT=SYS(5)+CURDIR()+'HZ.XLS'OEXL.WORKBOOKS.OPEN("&GFT")*OEXL.WORKSHEETS("HZ").ACTIVATE &&原代码OEXL.WORKSHEETS("SHEET1").ACTIVATE &&修改后代码*SELE HZCREATE CURSOR HZ (H01 N(2),H02 N(2),H03 N(2),H04 N(2),DQ C(3))INSERT INTO HZ VALUES (15,14,13,12,"001")INSERT INTO HZ VALUES (14,14,13,12,"002")INSERT INTO HZ VALUES (13,14,13,12,"004")LOCATE FOR DQ='001'IF .NOT. EOF() OEXL.ACTIVESHEET.CELLS(7,2).VALUE=HZ.H01 OEXL.ACTIVESHEET.CELLS(7,3).VALUE=HZ.H02 OEXL.ACTIVESHEET.CELLS(7,4).VALUE=HZ.H03 OEXL.ACTIVESHEET.CELLS(7,5).VALUE=HZ.H04ENDIF.LOCATE FOR DQ='002'IF .NOT. EOF() OEXL.ACTIVESHEET.CELLS(8,2).VALUE=HZ.H01 OEXL.ACTIVESHEET.CELLS(8,3).VALUE=HZ.H02 OEXL.ACTIVESHEET.CELLS(8,4).VALUE=HZ.H03 OEXL.ACTIVESHEET.CELLS(8,5).VALUE=HZ.H04ENDIFLOCATE FOR DQ='003'IF .NOT. EOF() OEXL.ACTIVESHEET.CELLS(9,2).VALUE=HZ.H01 OEXL.ACTIVESHEET.CELLS(9,3).VALUE=HZ.H02 OEXL.ACTIVESHEET.CELLS(9,4).VALUE=HZ.H03 OEXL.ACTIVESHEET.CELLS(9,5).VALUE=HZ.H04ENDIF*OEXL.WORKSHEETS("HZ").ACTIVATE &&原代码OEXL.WORKSHEETS("SHEET1").ACTIVATE &&修改后代码*---------临时添加,可以不用---------*IF !DIRECTORY(SYS(5)+CURDIR()+'汇总结果') MD SYS(5)+CURDIR()+'汇总结果'ENDIF*----------------------------------*LJ=SYS(5)+CURDIR()+'汇总结果\'+'汇总.XLS'OEXL.ACTIVEWORKBOOK.SAVEAS("&LJ")OEXL.VISIBLE=.T.*OEXL.WORKBOOKS.CLOSE*OEXL.QUITMESSAGEBOX("数据汇总成功!汇总文件位于汇总结果文件夹内!")