VB.NET 表格生成斜表头
详细代码如下,用VS代码可以直接复制使用,VBA则需要改一下
Private Sub 生成斜表头按钮_Click(sender As Object, e As RibbonControlEventArgs) Handles 生成斜表头按钮.Click
'获取行标题和列标题
Dim icol As String = InputBox("请输入斜线单元格的行标题", "行标题")
Dim irow As String = InputBox("请输入斜线单元格的列标题", "列标题")
app.Selection.Value = icol + Chr(10) + irow
'判断字符串是否符合规定
If Len(icol) = 0 Or Len(irow) = 0 Then
MsgBox("输入的标题为空!")
Exit Sub
End If
'判断选区是否只有一个单元格
If app.Selection.Count <> 1 Then
MsgBox("请选择一个单元格再执行此操作!")
Exit Sub
End If
'设置左上至右下的斜线
With app.Selection.Borders(Excel.XlBordersIndex.xlDiagonalDown)
.LineStyle = Excel.XlLineStyle.xlContinuous
.Weight = Excel.XlBorderWeight.xlThin
.ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With
End Sub
Private Sub 生成斜表头按钮_Click(sender As Object, e As RibbonControlEventArgs) Handles 生成斜表头按钮.Click
'获取行标题和列标题
Dim icol As String = InputBox("请输入斜线单元格的行标题", "行标题")
Dim irow As String = InputBox("请输入斜线单元格的列标题", "列标题")
app.Selection.Value = icol + Chr(10) + irow
'判断字符串是否符合规定
If Len(icol) = 0 Or Len(irow) = 0 Then
MsgBox("输入的标题为空!")
Exit Sub
End If
'判断选区是否只有一个单元格
If app.Selection.Count <> 1 Then
MsgBox("请选择一个单元格再执行此操作!")
Exit Sub
End If
'设置左上至右下的斜线
With app.Selection.Borders(Excel.XlBordersIndex.xlDiagonalDown)
.LineStyle = Excel.XlLineStyle.xlContinuous
.Weight = Excel.XlBorderWeight.xlThin
.ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With
End Sub
Sub 生成斜线表头()
'获取行标题和列标题
Dim icol, irow As String
icol = InputBox("请输入斜线单元格的行标题", "行标")
irow = InputBox("请输入斜线单元格的列标题", "列标题")
Selection.Value = icol + " " + irow
'判断字符串是否符合规定
If Len(icol) = 0 Or Len(irow) = 0 Then
MsgBox ("输入的标题为空!")
Exit Sub
End If
'判断选区是否只有一个单元格
If Selection.Count <> 1 Then
MsgBox ("请选择一个单元格再执行此操作!")
Exit Sub
End If
'设置左上至右下的斜线
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub