完成作业 但是有一点总是不对
Private Sub Command2_Click()
Set XlApp = CreateObject("Excel.Application")
Set XlBook = XlApp.Workbooks.Open(App.Path & "\book.xls")
Set XlSheet = XlBook.Worksheets("Sheet1")
XlSheet.Range("A1:IV65536").Clear
Dim i As Integer
For i = 0 To StudentCount
If i = 0 Then
XlSheet.Cells.Item(1, 1) = "语文"
XlSheet.Cells.Item(1, 2) = "数学"
XlSheet.Cells.Item(1, 3) = "英语"
XlSheet.Cells.Item(1, 4) = "文综/理综"
XlSheet.Cells.Item(1, 9) = "平均分"
XlSheet.Cells.Item(1, 8) = "最高分"
XlSheet.Cells.Item(2, 7) = "语文"
XlSheet.Cells.Item(3, 7) = "数学"
XlSheet.Cells.Item(4, 7) = "英语"
XlSheet.Cells.Item(5, 7) = "文综/理综"
XlSheet.Cells.Item(1, 5) = "高考成绩"
Else
XlSheet.Cells.Item(i + 1, 1) = Sorce_arry(i).Sorce1
XlSheet.Cells.Item(i + 1, 2) = Sorce_arry(i).Sorce2
XlSheet.Cells.Item(i + 1, 3) = Sorce_arry(i).Sorce3
XlSheet.Cells.Item(i + 1, 4) = Sorce_arry(i).Sorce4
End If
Next i
Dim cj As Integer
For cj = 1 To StudentCount
If cj = 1 Then
XlSheet.Cells.Item(cj + 1, 5) = XlSheet.Cells.Item(cj + 1, 1) + XlSheet.Cells.Item(cj + 1, 2) + XlSheet.Cells.Item(cj + 1, 3) + XlSheet.Cells.Item(cj + 1, 4)
XlSheet.Cells.Item(cj + 2, 5) = XlSheet.Cells.Item(cj + 2, 1) + XlSheet.Cells.Item(cj + 2, 2) + XlSheet.Cells.Item(cj + 2, 3) + XlSheet.Cells.Item(cj + 2, 4)
XlSheet.Cells.Item(cj + 3, 5) = XlSheet.Cells.Item(cj + 3, 1) + XlSheet.Cells.Item(cj + 3, 2) + XlSheet.Cells.Item(cj + 3, 3) + XlSheet.Cells.Item(cj + 3, 4)
XlSheet.Cells.Item(cj + 4, 5) = XlSheet.Cells.Item(cj + 4, 1) + XlSheet.Cells.Item(cj + 4, 2) + XlSheet.Cells.Item(cj + 4, 3) + XlSheet.Cells.Item(cj + 4, 4)
End If
Next cj
Dim av As Integer
For av = 1 To StudentCount
If av = 1 Then
XlSheet.Cells.Item(2, 9) = (XlSheet.Cells.Item(av + 1, 1) + XlSheet.Cells.Item(av + 2, 1) + XlSheet.Cells.Item(av + 3, 1) + XlSheet.Cells.Item(av + 4, 1)) / StudentCount
XlSheet.Cells.Item(3, 9) = (XlSheet.Cells.Item(av + 1, 2) + XlSheet.Cells.Item(av + 2, 2) + XlSheet.Cells.Item(av + 3, 2) + XlSheet.Cells.Item(av + 4, 2)) / StudentCount
XlSheet.Cells.Item(4, 9) = (XlSheet.Cells.Item(av + 1, 3) + XlSheet.Cells.Item(av + 2, 3) + XlSheet.Cells.Item(av + 3, 3) + XlSheet.Cells.Item(av + 4, 3)) / StudentCount
XlSheet.Cells.Item(5, 9) = (XlSheet.Cells.Item(av + 1, 4) + XlSheet.Cells.Item(av + 2, 4) + XlSheet.Cells.Item(av + 3, 4) + XlSheet.Cells.Item(av + 4, 4)) / StudentCount
End If
Next av
Dim tmax As Double, b As Integer
tmax = Sorce_arry(i).Sorce1
For b = 1 To -1
If Sorce_arry(i + 1).Sorce1 > tmax Then
tmax = Sorce_arry(i + 1).Sorce1
XlSheet.Cells.Item(2, 8) = Sorce_arry(i + 1).Sorce1
End If
Next b
Dim tmaa As Double, c As Integer
tmaa = Sorce_arry(i).Sorce2
For c = 1 To -1
If Sorce_arry(i + 1).Sorce2 > tmaa Then
tmaa = Sorce_arry(i + 1).Sorce2
XlSheet.Cells.Item(3, 8) = Sorce_arry(i + 1).Sorce2
End If
Next c
Dim tmab As Double, d As Integer
tmax = Sorce_arry(i).Sorce3
For d = 1 To -1
If Sorce_arry(i + 1).Sorce3 > tmab Then
tmab = Sorce_arry(i + 1).Sorce3
XlSheet.Cells.Item(4, 8) = Sorce_arry(i + 1).Sorce3
End If
Next d
Dim tmac As Double, e As Integer
tmac = Sorce_arry(i).Sorce4
For e = 1 To -1
If Sorce_arry(i + 1).Sorce4 > tmac Then
tmac = Sorce_arry(i + 1).Sorce4
XlSheet.Cells.Item(5, 8) = Sorce_arry(i + 1).Sorce4
End If
Next e
XlBook.Save
XlBook.Close (True)
Set XlApp = Nothing
MsgBox "写入Excle成功"
End Sub
Private Sub Command2_Click()
Set XlApp = CreateObject("Excel.Application")
Set XlBook = XlApp.Workbooks.Open(App.Path & "\book.xls")
Set XlSheet = XlBook.Worksheets("Sheet1")
XlSheet.Range("A1:IV65536").Clear
Dim i As Integer
For i = 0 To StudentCount
If i = 0 Then
XlSheet.Cells.Item(1, 1) = "语文"
XlSheet.Cells.Item(1, 2) = "数学"
XlSheet.Cells.Item(1, 3) = "英语"
XlSheet.Cells.Item(1, 4) = "文综/理综"
XlSheet.Cells.Item(1, 9) = "平均分"
XlSheet.Cells.Item(1, 8) = "最高分"
XlSheet.Cells.Item(2, 7) = "语文"
XlSheet.Cells.Item(3, 7) = "数学"
XlSheet.Cells.Item(4, 7) = "英语"
XlSheet.Cells.Item(5, 7) = "文综/理综"
XlSheet.Cells.Item(1, 5) = "高考成绩"
Else
XlSheet.Cells.Item(i + 1, 1) = Sorce_arry(i).Sorce1
XlSheet.Cells.Item(i + 1, 2) = Sorce_arry(i).Sorce2
XlSheet.Cells.Item(i + 1, 3) = Sorce_arry(i).Sorce3
XlSheet.Cells.Item(i + 1, 4) = Sorce_arry(i).Sorce4
End If
Next i
Dim cj As Integer
For cj = 1 To StudentCount
If cj = 1 Then
XlSheet.Cells.Item(cj + 1, 5) = XlSheet.Cells.Item(cj + 1, 1) + XlSheet.Cells.Item(cj + 1, 2) + XlSheet.Cells.Item(cj + 1, 3) + XlSheet.Cells.Item(cj + 1, 4)
XlSheet.Cells.Item(cj + 2, 5) = XlSheet.Cells.Item(cj + 2, 1) + XlSheet.Cells.Item(cj + 2, 2) + XlSheet.Cells.Item(cj + 2, 3) + XlSheet.Cells.Item(cj + 2, 4)
XlSheet.Cells.Item(cj + 3, 5) = XlSheet.Cells.Item(cj + 3, 1) + XlSheet.Cells.Item(cj + 3, 2) + XlSheet.Cells.Item(cj + 3, 3) + XlSheet.Cells.Item(cj + 3, 4)
XlSheet.Cells.Item(cj + 4, 5) = XlSheet.Cells.Item(cj + 4, 1) + XlSheet.Cells.Item(cj + 4, 2) + XlSheet.Cells.Item(cj + 4, 3) + XlSheet.Cells.Item(cj + 4, 4)
End If
Next cj
Dim av As Integer
For av = 1 To StudentCount
If av = 1 Then
XlSheet.Cells.Item(2, 9) = (XlSheet.Cells.Item(av + 1, 1) + XlSheet.Cells.Item(av + 2, 1) + XlSheet.Cells.Item(av + 3, 1) + XlSheet.Cells.Item(av + 4, 1)) / StudentCount
XlSheet.Cells.Item(3, 9) = (XlSheet.Cells.Item(av + 1, 2) + XlSheet.Cells.Item(av + 2, 2) + XlSheet.Cells.Item(av + 3, 2) + XlSheet.Cells.Item(av + 4, 2)) / StudentCount
XlSheet.Cells.Item(4, 9) = (XlSheet.Cells.Item(av + 1, 3) + XlSheet.Cells.Item(av + 2, 3) + XlSheet.Cells.Item(av + 3, 3) + XlSheet.Cells.Item(av + 4, 3)) / StudentCount
XlSheet.Cells.Item(5, 9) = (XlSheet.Cells.Item(av + 1, 4) + XlSheet.Cells.Item(av + 2, 4) + XlSheet.Cells.Item(av + 3, 4) + XlSheet.Cells.Item(av + 4, 4)) / StudentCount
End If
Next av
Dim tmax As Double, b As Integer
tmax = Sorce_arry(i).Sorce1
For b = 1 To -1
If Sorce_arry(i + 1).Sorce1 > tmax Then
tmax = Sorce_arry(i + 1).Sorce1
XlSheet.Cells.Item(2, 8) = Sorce_arry(i + 1).Sorce1
End If
Next b
Dim tmaa As Double, c As Integer
tmaa = Sorce_arry(i).Sorce2
For c = 1 To -1
If Sorce_arry(i + 1).Sorce2 > tmaa Then
tmaa = Sorce_arry(i + 1).Sorce2
XlSheet.Cells.Item(3, 8) = Sorce_arry(i + 1).Sorce2
End If
Next c
Dim tmab As Double, d As Integer
tmax = Sorce_arry(i).Sorce3
For d = 1 To -1
If Sorce_arry(i + 1).Sorce3 > tmab Then
tmab = Sorce_arry(i + 1).Sorce3
XlSheet.Cells.Item(4, 8) = Sorce_arry(i + 1).Sorce3
End If
Next d
Dim tmac As Double, e As Integer
tmac = Sorce_arry(i).Sorce4
For e = 1 To -1
If Sorce_arry(i + 1).Sorce4 > tmac Then
tmac = Sorce_arry(i + 1).Sorce4
XlSheet.Cells.Item(5, 8) = Sorce_arry(i + 1).Sorce4
End If
Next e
XlBook.Save
XlBook.Close (True)
Set XlApp = Nothing
MsgBox "写入Excle成功"
End Sub