注意多新建一个工作表
- Sub 数据读取()
- Dim myFso As New FileSystemObject
- Dim myTs As TextStream
- Dim str$, i As Integer, je As Double, m As Integer, x As Integer
- Set myTs = myFso.OpenTextFile(ThisWorkbook.Path & "\成绩单.txt")
- With Sheet2
- Do Until myTs.AtEndOfStream
- m = m + 1
- .Cells(m, 1).Resize(1, 4) = Split(myTs.ReadLine, Chr(9))
- Loop
- .Cells(1, 5).Resize(1, 3) = Array("总分", "平均分", "升留级")
- Sheet3.Cells(1, 1).Resize(1, 3) = Array("ID", "科目", "成绩")
- x = 1
- For i = 2 To m
- je = 0
- For j = 2 To 4
- x = x + 1
- Sheet3.Cells(x, 1) = .Cells(i, 1)
- Sheet3.Cells(x, 2) = .Cells(1, j)
- Sheet3.Cells(x, 3) = .Cells(i, j) * 1
- .Cells(i, j) = .Cells(i, j) * 1
- je = .Cells(i, j) + je
- Next
- .Cells(i, 5) = je
- .Cells(i, 6) = je / 3
- If je / 3 > 60 Then .Cells(i, 7) = "升级" Else .Cells(i, 7) = "留级"
- Next
- End With
- With Sheet3.Range("A1").CurrentRegion
- .Borders.LineStyle = True
- .Font.Size = 9
- .EntireRow.RowHeight = 14.25
- End With
- End Sub
复制代码 |