easyexcel写斜线表头代码
时间: 2023-09-26 13:13:14 浏览: 109
EasyExcel导出.txt
5星 · 资源好评率100%
Sub DrawDiagonalHeader()
Dim ws As Worksheet
Set ws = ActiveSheet
'设置表头样式
With ws.Range("A1:E1")
.Merge
.Value = "斜线表头"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Size = 16
.Font.Bold = True
End With
'设置斜线样式
With ws.Range("A2:E2")
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeTop).ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeBottom).ColorIndex = xlAutomatic
.Borders(xlDiagonalUp).LineStyle = xlContinuous
.Borders(xlDiagonalUp).Weight = xlThin
.Borders(xlDiagonalUp).ColorIndex = xlAutomatic
.Borders(xlDiagonalDown).LineStyle = xlContinuous
.Borders(xlDiagonalDown).Weight = xlThin
.Borders(xlDiagonalDown).ColorIndex = xlAutomatic
.Interior.ColorIndex = 15 '设置背景色
End With
'填充数据
ws.Range("A2") = "1"
ws.Range("B2") = "2"
ws.Range("C2") = "3"
ws.Range("D2") = "4"
ws.Range("E2") = "5"
'自动调整列宽
ws.Columns.AutoFit
End Sub
阅读全文