Excel操作——单元格的边框

来源:互联网 发布:手机淘宝怎么注册不上 编辑:程序博客网 时间:2024/05/17 19:59

边框的属性主要有四个:颜色,颜色索引(无实际意义),线条类型,线条粗细。

     获得一个单元格的边框信息可使用如下方式:

     Borders oBorders;

     Border oBorder;

     oBorders = oCurCell.GetBorders();

     // Borders包含一个单元格的几种线条:上、下、左、右边,两条对角线

     // 1 左边

     // 2 右边

     // 3 上边

     // 4 下边

     // 5 斜下对角线

     // 6 斜上对角线

     oBorder.AttachDispatch(oBorders.GetItem(2));          

     VARIANT varLineStyle = oBorder.GetLineStyle();         // 线条类型

     VARIANT varWeight = oBorder.GetWeight();                // 线条粗细

     VARIANT varColor = oBorder.GetColor();                  // 线条颜色

     VARIANT varColorIndex = oBorder.GetColorIndex();      // 颜色索引

 

     设定一个单元格的边框也是这四个属性,可以根据边设置,使用下面方法:

     Borders oBorders;

     oBorders = oCurCell.GetBorders();

     // Borders包含一个单元格的几种线条:上、下、左、右边,两条对角线

     // 1 左边

     // 2 右边

     // 3 上边

     // 4 下边

     // 5 斜下对角线

     // 6 斜上对角线

    oBorder.AttachDispatch(oBorders.GetItem(2));

    oBorder.SetLineStyle( varLineStyle );

    oBorder.SetWeight( varWeight );

    oBorder.SetColor( varColor );

    oBorder.SetColorIndex( varColorIndex );

    也可以使用BorderAround函数为单元格设置同样的边框。该函数的四个参数如下:

1.        边框类型

2.        边框粗细

3.        颜色

4.        颜色索引

有一点请注意:顺序在后的单元格边框会覆盖前面的边框。

 

下面说明LineStyle的值。下图是Excel设置LineStyle的界面,

 

 

我将从左至右,从上至下逐一说明。

序号

LineStyle

Weight

Color

1.           

-4142

2

0

2.           

1

1

0

3.           

-4118

2

0

4.           

5

2

0

5.           

4

2

0

6.           

-4115

2

0

7.           

1

2

0

8.           

5

-4138

0

9.           

13

-4138

0

10.        

4

-4138

0

11.        

-4115

-4138

0

12.        

1

-4138

0

13.        

1

4

0

14.        

-4119

4

0

 

         注意:

         我在实现的过程中发现几个与想象中不同的地方。

1.         ( -4142, 2, 0 )应该是none,实际画出来会是一条黑色的实线,起关键作用的是Weight为2。

2.         ( 1, 1, 0 )是一条虚线,( 1, 2, 0 )是一条实线,后者可以覆盖前者,但是前者无法覆盖后者。

原创粉丝点击