silasiqq 发表于 2008-1-17 15:31

求助:vfp如何控制excel的sheet

如何把一个学生成绩表,分别按 班级 导出excel中不同的sheet中。比如:把一班的成绩导出到sheet1中,把二班的成绩导出到sheet2中。请高手们帮忙,在此,先谢谢高手们了!

Tiger5392 发表于 2008-1-17 16:56

create cursor Student (班级 C(10),学号 C(8),姓名 C(8),性别 C(2))
insert into Student Values ('经济04-1','B0401001','张三','男')
insert into Student Values ('经济04-1','B0401002','李四','男')
insert into Student Values ('经济04-2','B0401003','王五','男')
insert into Student Values ('经济04-2','B0401004','赵六','男')
insert into Student Values ('经济04-3','B0401005','孙启','男')
insert into Student Values ('经济04-3','B0401006','周把','男')
insert into Student Values ('经济05-1','B0501001','乌桕','男')
insert into Student Values ('经济05-1','B0501002','手动','男')
insert into Student Values ('经济05-1','B0501003','风格','男')
insert into Student Values ('经济06-1','B0601001','规划','男')
insert into Student Values ('经济06-1','B0601002','沟通','男')
select * from student order by 1 into cursor st
select count(*) as amount from student group by 班级 into cursor st1
select st1
lnSheets=reccount('st1')
o=NewObject('Excel.Application')
o.workbooks.add
o.visible=.t.
do while o.workbooks(1).worksheets.count<lnSheets
  o.workbooks(1).worksheets.add
enddo
select st
lcClass=space(100)
lnCnt=0
lnRow=1
scan
  if lcClass#班级
    lnCnt=lnCnt+1
    lnRow=1
    lcClass=班级
    o.workbooks(1).worksheets(lnCnt).name=lcClass
  endif
  o.workbooks(1).worksheets(lnCnt).cells(lnRow,1).value=班级
  o.workbooks(1).worksheets(lnCnt).cells(lnRow,2).value=学号
  o.workbooks(1).worksheets(lnCnt).cells(lnRow,3).value=姓名
  o.workbooks(1).worksheets(lnCnt).cells(lnRow,4).value=性别
  lnRow=lnRow+1
endscan

baichuan 发表于 2008-1-18 07:56

还是大老虎给的详细!

silasiqq 发表于 2008-1-19 15:32

谢谢大家的帮助,再次感谢!

页: [1]

编程论坛