Sub MakeSheet(ByVal N As String, C As Integer, pY As Integer, hbC As Integer)
'适用性: 最大行数:500,第一列无空格,最大到N列,题头3行
'参数含义: N:sheet表名 pY:每页行数(除题头) C:字段数 Colu:要合并的列数
Dim r1 As Integer '当前对比起始行,合并时用
Screen.MousePointer = vbHourglass
Set wSheet = AppExcel.Worksheets(N)
With wSheet
.Range("a4:n500").ClearContents
.Range("a4:n500").MergeCells = False
.Cells(1, 1) = SBar.Panels(1).Text
grRs.MoveFirst
For i = 1 To grRs.RecordCount
For j = 1 To C
.Cells(3 + i, j) = grRs.Fields(j - 1).Value
Next j
grRs.MoveNext
Next
'以下为合并单元格部分
If hbC > 0 Then
For p = 4 To 500 Step pY
For Colu = hbC To 1 Step -1 '列
r1 = p
For r = p + 1 To p + pY - 1 '行
If .Cells(r, 1) = "" Then Exit For '第一列无数据,退出
If .Cells(r, Colu) <> .Cells(r1, Colu) Then
If .Cells(r1, Colu) <> "" Then .Range(.Cells(r1, Colu), .Cells(r - 1, Colu)).Merge
.Cells(r1, Colu).VerticalAlignment = xlCenter
r1 = r
ElseIf r = p + pY - 1 And r <> r1 Then
.Cells(r, Colu) = ""
.Range(.Cells(r1, Colu), .Cells(r, Colu)).Merge
.Cells(r1, Colu).VerticalAlignment = xlCenter
Else
.Cells(r, Colu) = ""
If .Cells(r + 1, 1) = "" Then
.Range(.Cells(r1, Colu), .Cells(r, Colu)).Merge
.Cells(r1, Colu).VerticalAlignment = xlCenter
End If
End If
Next r
Next Colu
If .Cells(r, 1) = "" Then Exit For
Next p
End If
.PrintOut