用vb+excel做学生成绩管理系统
遇到这样一个问题
在按专业打印学生毕业成绩单时,按学期的课程要在一行内打印,如英语是四个学期要打印在一行中,怎么才能实现?
我是利用rs1是取出一个专业中的学生名单
利用rs2从学生成绩总库中取出某一学生成绩
str=select * from xsjbxxz where o_zymc='" & txtzy.text & "'"
rs1.open str
t_xh=o_xh
if not rs1.recordcount()>0 then
   do while not rs1.eof()
          str=select * from xscjzb where o_xh='" & t_xh & "' order by o_xq" 
          rs2.open str
   if  rs2.recordcount()>0 then
……
怎么修改才能达到要求?

解决方案 »

  1.   

    你是要实现在excel中显示要打印的东西,还是要实现从表中取出一个学生的四年成绩?
    打印到excel要在引用中加入excel的引用.microsoft excel9.0 object libraryPrivate Sub btExcel_Click()
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)' Make Excel visible through the Application object.
    xlApp.Application.Visible = True
    ' Place some text in the first cell of the sheet.
    xlApp.Cells(1, 1).Value = "This is column A, row 1"
    For i = 5 To 10
    For j = 5 To 100
    xlSheet.Cells(i, j).Value = i * j
    Next
    Next'    xlSheet.Range("E5:J10").Select
        xlApp.Charts.Add
        xlApp.ActiveChart.ChartType = xlColumnClustered
        xlApp.ActiveChart.SetSourceData Source:=xlSheet.Range("E5:J10"), PlotBy _
            :=xlRows
        xlApp.ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"' Save the sheet to C:\test.doc directory.
    xlBook.SaveAs "C:\ TEST.xls"
    ' Close Excel with the Quit method on the Application object.
    xlApp.Application.Quit
    ' Release the object variable.
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
    End Sub
    在xlSheet.Cells(i, j).Value后面加入要打印的内容就可以了
    在循环中来控制