向 NamedRange 控件添加一个边框,并设置新边框的 Color、LineStyle 和 Weight 属性。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Function BorderAround ( _
    LineStyle As Object, _
    Weight As XlBorderWeight, _
    ColorIndex As XlColorIndex, _
    Color As Object _
) As Object
Object BorderAround(
    Object LineStyle,
    XlBorderWeight Weight,
    XlColorIndex ColorIndex,
    Object Color
)
参数
- LineStyle
 类型:System.Object
 边框的线型。可以是下列 XlLineStyle 值之一:
 xlContinuous
 xlDash
 xlDashDot
 xlDashDotDot
 xlDot
 xlDouble
 xlSlantDashDot
 xlLineStyleNone
- Weight
 类型:Microsoft.Office.Interop.Excel.XlBorderWeight
 边框的粗细。可以是下列 XlBorderWeight 常量之一:
 xlHairline
 xlMedium
 xlThick
 xlThin
- ColorIndex
 类型:Microsoft.Office.Interop.Excel.XlColorIndex
 边框颜色(作为访问当前调色板的索引或作为 XlColorIndex 常数)。可以是下列 XlColorIndex 常数之一:
 xlColorIndexAutomatic
 xlColorIndexNone
- Color
 类型:System.Object
 边框颜色,采用 RGB 值的形式。
返回值
备注
必须指定 ColorIndex 或 Color,但是不能同时指定二者。
可以指定 LineStyle 或 Weight,但是不能同时指定二者。 如果没有指定任何参数,则 Microsoft Office Excel 将使用默认的线型和粗细。
此方法绘制整个范围而不填充它。 若要设置所有单元格的边框,必须设置 Borders 集合的 Color、LineStyle 和 Weight 属性。 若要清除边框,必须将该范围中所有单元格的 LineStyle 属性设置为 xlLineStyleNone。
可选参数
有关可选参数的信息,请参见Office 解决方案中的可选参数。
示例
下面的代码示例演示如何设置各种格式以及显示名为 NamedRange1 的 NamedRange 控件的特征。 特别是,此示例使用 BorderAround 方法在 NamedRange1 周围绘制粗边框。
此示例针对的是文档级自定义项。
    Private Sub SetRangeFormats()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
            "namedRange1")
        namedRange1.NoteText("This is a Formatting test", , )
        namedRange1.Value2 = "Martha"
        namedRange1.Font.Name = "Verdana"
        namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
        namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
        namedRange1.BorderAround(, Excel.XlBorderWeight.xlThick, _
            Excel.XlColorIndex.xlColorIndexAutomatic, )
        namedRange1.AutoFormat( _
            Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1, _
            True, False, True, False, True, True)
        If MessageBox.Show("Clear the formatting and notes?", _
            "Test", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            namedRange1.ClearFormats()
            namedRange1.ClearNotes()
        End If
    End Sub
private void SetRangeFormats()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");
    namedRange1.NoteText("This is a Formatting test", missing, missing);
    namedRange1.Value2 = "Martha";
    namedRange1.Font.Name = "Verdana";
    namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
    namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
    namedRange1.BorderAround(missing, Excel.XlBorderWeight.xlThick,
        Excel.XlColorIndex.xlColorIndexAutomatic, missing);
    namedRange1.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1,
        true, false, true, false, true, true);
    if (MessageBox.Show("Clear the formatting and notes?", "Test",
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        namedRange1.ClearFormats();
        namedRange1.ClearNotes();
    }
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。