现在有一个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").Activate
Sele hz
Locate 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.h04
Endif.
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.h04
Endif
Locate 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.h04
Endif
oexl.worksheets("hz").Activate
lj=Sys(5)+Curdir()+'汇总结果\'+'汇总.xls'
oexl.activeworkbook.SaveAs("&lj")
oexl.workbooks.Close
oexl.Visible=.T.
oexl.Quit
Messagebox("数据汇总成功!汇总文件位于汇总结果文件夹内!")
------解决方案--------------------------------------------------------
OEXL=CREATEOBJECT("EXCEL.APPLICATION")
GFT=SYS(5)+CURDIR()+'HZ.XLS'
OEXL.WORKBOOKS.OPEN("&GFT")
*OEXL.WORKSHEETS("HZ").ACTIVATE &&原代码
OEXL.WORKSHEETS("SHEET1").ACTIVATE &&修改后代码
*SELE HZ
CREATE 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