2011年5月9日月曜日

セルに罫線をひく

Sub ExampleSetBorderLine()
       Dim objSheet As Object
       Dim objCell As Object

       Dim objBorderLine1 As New com.sun.star.table.BorderLine
       Dim objBorderLine2 As New com.sun.star.table.BorderLine
       Dim objBorderLine3 As New com.sun.star.table.BorderLine
       Dim objBorderLine4 As New com.sun.star.table.BorderLine
       '
       '黒の単線
       With objBorderLine1
              .Color = RGB(0, 0, 0)
              .OuterLineWidth = 88
       End With
       '
       '赤の二重線
       With objBorderLine2
              .Color = RGB(255, 0, 0)
              .InnerLineWidth = 35
              .OuterLineWidth = 88
              .LineDistance = 88 
       End With
       '
       '緑の単線
       With objBorderLine3
              .Color = RGB(0, 255, 0)
              .OuterLineWidth = 88
       End With
       '
       '青の二重線
       With objBorderLine4
              .Color = RGB(0, 0, 255)
              .InnerLineWidth = 35
              .OuterLineWidth = 88
              .LineDistance = 88 
       End With
       '
       objSheet = ThisComponent.CurrentController.ActiveSheet
       objCell = objSheet.getCellRangeByName("B2")
       WIth objCell
              .LeftBorder = objBorderLine1
              .RightBorder = objBorderLine2
              .TopBorder = objBorderLine3
              .BottomBorder = objBorderLine4
       End With
End Sub
  
セルに罫線をひくための手順は下記の通り :
  
1. com.sun.star.table.BorderLine オブジェクトの下記四つのプロパティに
   値を設定する。
   ① Color : 罫線の色。
   ② InnerLineWidth : 二重線の内側の線の太さ。単線の場合は設定不要。
   ③ OuterLineWidth : 二重線の外側、または、単線の太さ。
   ④ LineDistance : 二重線の線の間の間隔。単線の場合は設定不要。
  
2. セルオブジェクトの左側、右側、上側、下側を表すそれぞれのプロパティ
      LeftBorder、RightBorder、TopBorder、BottomBorder
   に、1. で設定したオブジェクトを指定する。
  
マクロの実行結果は下図の通り :
  
BorderLine オブジェクトの InnerLineWidth、OuterLineWidth、LineDistance
に指定されている値は太さを表す数値だが、
    ・ 0.05pt の場合は 「2」
    ・ 1pt の場合は 「35」
    ・ 2.5pt の場合は 「88」
    ・ 4pt の場合は 「141」
    ・ 5pt の場合は 「176」
という具合に指定するそうだ(参考文献 (8) を参照)。

0 件のコメント:

コメントを投稿