セルの外枠と影 
枠 
枠線を設定するには, LeftBorder, RightBorder, TopBorder, BottomBorder, プロパティーまたは, TableBorder プロパティーを使用します。
TableBorder 以外の 4 つのプロパティーはセルやセル範囲の一辺だけの枠線です。
線 
枠に線を設定するにはまず,枠線を用意する必要があります。この枠線は com.sun.star.table.BorderLine struct で用意します。この struct の要素は Color, OuterLineWidth, InnerLineWidth, LineDistance です。
Dim oBorderLine1 As New com.sun.star.table.BorderLine
oBorderLine1.Color = RGB( 255, 0, 0 ) ' red
oBorderLine1.OuterLineWidth = 88 'in 1/100th mm
上の例では,赤色の幅 2.5 pt の単線をつくっています。OuterLineWidth を指定しなければ線はないことになります。二重線にするときは,InnerLineWidth も設定します。また,そのときは二本の線の間隔を LineDistance で設定します。
Dim oBorderLine2 As New com.sun.star.table.BorderLine
oBorderLine2.InnerLineWidth= 2
oBorderLine2.OuterLineWidth = 141
oBorderLine2.LineDistance = 88
上の例では 6.55 pt の幅の二重線をつくっています。
枠の設定 
枠線をつくったら,つぎはその枠線を枠に設定します。 LeftBorder, RightBorder, TopBorder, BottomBorder ではそのまま代入するだけです。
Sub Border_set()
Dim oBorderLine3 As Object
oBorderLine3 = createUnoStruct( "com.sun.star.table.BorderLine" )
oBorderLine3.InnerLineWidth = 100
oBorderLine3.OuterLineWidth = 1000
oBorderLine3.LineDistance = 200
oSheet = ThisComponent.CurrentController.ActiveSheet
oCell = oSheet.getCellRangeByName( "D5" )
oCell.BottomBorder = oBorderLine3
End Sub
上のコードを実行すると,"D5" セルの下側の枠が設定されます。このように幅の広い線も設定できます。ほかの三辺も同様に設定できます。
TableBorder を用いる場合は,少し違います。TableBorder をcom.sun.star.table.TableBorder struct で設定する必要があります。
上の例と同じ様にするには,次のようにします。
Dim oTableBorder As New com.sun.star.table.TableBorder
oTableBorder.IsBottomLineValid = True
oTableBorder.BottomLine = oBorderLine3
Cell.TableBorder = oTableBorder
枠線ごとに Is...LineValid があり,枠線を使用する部分のものを True にしなければ線が引かれません。
セル範囲に枠を設定する場合には,範囲のセル全ての横線と縦線を引くこともできます。
Sub tableborder_cellrange()
Dim oSheet As Object, oCellRange As Object
Dim oTableBorder As New com.sun.star.table.TableBorder
Dim oBorderLineBlue As New com.sun.star.table.BorderLine
Dim oBorderLineRed As New com.sun.star.table.BorderLine
oSheet = ThisComponent.CurrentController.ActiveSheet
oCellRange = oSheet.getCellRangeByName( "B2:D7" )
oBorderLineBlue.Color = RGB( 0, 0, 255 )
oBorderLineBlue.OuterLineWidth = 2 ' 0.05 pt
oBorderLineRed.Color = RGB( 255, 0, 0 )
oBorderLineRed.OuterLineWidth = 20
oTableBorder.IsHorizontalLineValid = True
oTableBorder.HorizontalLine = oBorderLineBlue
oTableBorder.IsVerticalLineValid = True
oTableBorder.VerticalLine = oBorderLineRed
oCellRange.TableBorder = oTableBorder
End Sub
縦線と横線がセルの間にも引かれます。周りの枠線は設定していないので線が引かれません。
影 
影の設定には ShadowFormat プロパティーを使用します。このプロパティーは com.sun.star.table.ShadowFormat struct で設定します。
Sub shadowformat()
Dim oSheet As Object, oCell As Object
Dim oShadowFormat As New com.sun.star.table.ShadowFormat
oSheet = ThisComponent.CurrentController.ActiveSheet
oCell = oSheet.getCellRangeByName( "B3" )
oCell.CellBackColor = RGB( 255, 128, 128 )
oShadowFormat.Color = RGB( 204, 204, 255 ) 'shadow color
oShadowFormat.Location = com.sun.star.table.ShadowLocation.TOP_LEFT
oShadowFormat.IsTransparent = False
oShadowFormat.ShadowWidth = 250 'in 1/100th mm
oCell.ShadowFormat = oShadowFormat
End Sub
上のコードを実行するとセルに影がつけられます。 IsTransparent を False にしないと表示されない場合があります。また,影がつく位置は Location で設定します。この Location は com.sun.star.table.ShadowLocation enum で選択します。
まとめ 
線の太さと各種プロパティー値を表にしました。枠線を設定するときに参考にしてください。
単線 |
pt | InnerLineWidth | OuterLineWidth | LineDistance |
なし | 0 | 0 | 0 |
0.05 | 0 | 2 | 0 |
1.00 | 0 | 35 | 0 |
2.50 | 0 | 88 | 0 |
4.00 | 0 | 141 | 0 |
5.00 | 0 | 176 | 0 |
二重線 |
pt | InnerLineWidth | OuterLineWidth | LineDistance |
1.10 | 2 | 2 | 35 |
2.60 | 2 | 2 | 88 |
3.00 | 35 | 35 | 35 |
7.50 | 88 | 88 | 88 |
3.55 | 2 | 35 | 88 |
5.05 | 2 | 88 | 88 |
6.55 | 2 | 141 | 88 |
6.00 | 35 | 88 | 88 |
4.50 | 88 | 35 | 35 |
9.00 | 88 | 141 | 88 |
9.00 | 141 | 88 | 88 |
OuterLineWidth が 0 の時には線が引かれておらず,単線の時には LineDistance および InnerLineWidth が 0 です。