|
- Sub test()
- Dim r%, i%, m%
- Dim arr, brr, crr(1 To 10000, 1 To 6), zrr()
- Dim mypath$, myname$
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- mypath = ThisWorkbook.Path & ""
- myname = "1.txt"
- If Dir(mypath & myname) = "" Then
- MsgBox "1.txt文件不存在!"
- Exit Sub
- End If
- Open mypath & myname For Input As #1
- arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
- Close #1
- m = 0
- x = 0
- For i = 0 To UBound(arr)
- ss = Replace(arr(i), Space(1), "")
- If InStr(ss, "课表") <> 0 Then
- m = m + 1
- x = x + 1
- crr(m, 1) = ss
- ReDim Preserve zrr(1 To x)
- zrr(x) = Array(m, m)
- ElseIf InStr(ss, "│") <> 0 Then
- brr = Split(ss, "│")
- If UBound(brr) = 7 Then
- m = m + 1
- For j = 1 To 6
- crr(m, j) = brr(j)
- Next
- If x > 0 Then
- zrr(x)(1) = m
- End If
- End If
- End If
- Next
- ls = 3 + 5 * 7
- ReDim drr(1 To UBound(zrr), 1 To ls)
- For k = 1 To UBound(zrr)
- drr(k, 1) = crr(zrr(k)(0), 1)
- For j = 2 To UBound(crr, 2)
- n1 = j * 7 - 10
- n2 = 0
- For i = zrr(k)(0) + 2 To zrr(k)(1) Step 2
- n2 = n2 + 1
- drr(k, n1 + n2 - 1) = crr(i, j) & vbLf & crr(i + 1, j)
- Next
- Next
- Next
- With Worksheets("七年级")
- .Cells.Clear
- With .Range("a1")
- .Value = "课时班级"
- .Resize(2, 1).Merge
- End With
- n = 4
- For i = 1 To 5
- With .Cells(1, n)
- .Value = "周" & Application.Text(i, "[DBnum1]")
- .Resize(1, 7).Merge
- End With
- .Cells(2, n).Resize(1, 7) = Array(1, 2, 3, 4, 5, 6, 7)
- n = n + 7
- Next
- .Range("a3").Resize(UBound(drr), UBound(drr, 2)) = drr
- With .Range("a1").Resize(2 + UBound(drr), UBound(drr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|