Dim tbl As Table = CurrentTable
Dim hdr As Integer = tbl.HeaderRows '获得表头的层数
Dim cnt As Integer
Dim Book As New XLS.Book
Book.DefaultFont = New Font("宋体", 10) '设置默认字体
Dim Sheet As XLS.Sheet = Book.Sheets(0)
tbl.CreateSheetHeader(Sheet) '生成表头
Dim cnt_Cou As Integer = tbl.Cols.Count - 1
Dim row_Cou As Integer = tbl.Rows.Count - 1
Dim Style0 As Xls.Style = Book.NewStyle '新建一个样式
Dim Style1 As Xls.Style = Book.NewStyle '新建一个样式
'Sheet(r + hdr, cnt).Style.AlignVert = XLS.AlignVertEnum.Center
Style0.BackColor = Color.FromARGB(255, 202, 202, 202) '样式的背景颜色
Style1.BackColor = Color.FromARGB(255, 232, 232, 232) '样式的背景颜色
Dim 合并几行 As Integer = 1 '合并几行
For c As Integer = 0 To tbl.Cols.Count - 1
合并几行 = 1
If tbl.Cols(c).Visible Then
For hdri As Integer = 0 To hdr - 1 ' 表头行
Sheet(hdri, cnt).Style = style0
Sheet(hdri, cnt).Style.AlignHorz = XLS.AlignHorzEnum.Center
Sheet(hdri, cnt).Style.AlignVert = XLS.AlignVertEnum.Center
Next
For r As Integer = 0 To tbl.Rows.Count - 1 ' 循环所有行
Sheet(r + hdr, cnt).value = tbl(r, c).ToString
If r Mod 2 = 0 Then
sheet(r + hdr, cnt).Style = Style1
End If
If r > 0 Then
If tbl(r, c) = tbl(r - 1, c) Then ' 本行 上一行的值
合并几行 = 合并几行 + 1
'MessageBox.Show("r" & r & "c" & cnt & vbCrLf & "rc" & rc & vbCrLf & vbCrLf & tbl(r, c) & vbCrLf & tbl(r - 1, c))
Else
'MessageBox.Show("r" & r & "c" & cnt & vbCrLf & "rc" & rc & vbCrLf & vbCrLf & tbl(r, c) & vbCrLf & tbl(r - 1, c))
If 合并几行 > 1 Then
Output.SHOW("行:" & r + hdr - 合并几行 & " 列:" & cnt & " 合并几行:" & 合并几行)
Sheet.MergeCell(r + hdr - 合并几行 , cnt, 合并几行, 1)
End If
合并几行 = 1
End If
If r > 1 AndAlso r = tbl.Rows.Count - 1 AndAlso 合并几行 > 1 Then ' 最后一行
Output.SHOW("最后1行:" & "开始行:" & r + hdr - 合并几行 + 1 & " 列:" & cnt & " 合并几行:" & 合并几行)
Sheet.MergeCell( r + hdr - 合并几行 + 1 , cnt, 合并几行, 1)
End If
End If
Next
cnt = cnt + 1
End If
Next
For r As Integer = 0 To tbl.Rows.Count - 1 ' 循环所有行
sheet.rows(r + hdr).Height = tbl.Grid.rows(r).HeightDisplay ' 设置行高
' For c As Integer = 0 To Sheet.Cols.Count - 1
' Sheet(1, C).Style.AlignVert = XLS.AlignVertEnum.Center
' Next
Next
Sheet.rows(0).Style.AlignVert = XLS.AlignVertEnum.Center ' 这里不出错 ?
For U As Integer = 1 To Sheet.Rows.Count - 1
Sheet.rows(U).Style.AlignVert = XLS.AlignVertEnum.Center ' 这里执行为什么出错 ?
Next