ページ設定 
Calc シートのページ設定を変更します。
Calc シートのページ設定は,ページスタイルと関与しています。ページスタイルを使用していないと思っていてもメニューからページ設定を変更すると "Default" のスタイルが変更されます。
Calc でのページ設定にはスタイルを使用します。
ページスタイル 
今にシートで使用しているページスタイルは,シートオブジェクトの PageStyle プロパティーで知ることができます。
Sub pagestyle_1
Dim oDoc As Object, oSheet As Object
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex( 0 )
MsgBox oSheet.getPropertyValue( "PageStyle" )
End Sub
何も変更していないドキュメントのシートなら "Default" のページスタイルが使用されています。テンプレートなどから作成した場合には別のスタイルが使用されているかもしれません。
ページスタイルにアクセスするには,スタイルファーミリーコンテナからスタイルファーミリーを取得して,さらにスタイルを取得します。何のことやら分からないので次のコードをみてください。
Sub pagestyle_2
Dim oStyleFamilies As Object, oPageStyles As Object
Dim oPageStyle As Object
Dim oDoc As Object, oSheet As Object
Dim sStyles() As String
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex( 0 )
oStyleFamilies = oDoc.getStyleFamilies() ' --1
oPageStyles = oStyleFamilies.getByName( "PageStyles" ) ' --2
sStyles() = oPageStyles.getElementNames()
For i% = 0 To UBound( sStyles() )
MsgBox sStyles(i)
Next i
If oPageStyles.hasByName( "Default" ) Then
oPageStyle = oPageStyles.getByName( "Default" ) ' --3
Globalscope.BasicLibraries.LoadLibrary( "mytools" )
End If
End Sub
最初はドキュメントの持つページスタイルは "Default" と "Report" の二つだけです。
"1" の行はスタイルを使用するときにいつも使用します。StyleFamilies container とよばれるようです。"2" の行は oStyleFamilies のなかから "PageStyles" スタイルファミリーを取得しています。 spreadsheet ドキュメントでは "CellStyles" と "PageStyles" の二つがあります。"3" の行では "Default" のスタイル名を持つスタイルオブジェクトを取得しています。
変更 
ただページの設定を変更するだけで新しいページスタイルを作成しなければ簡単です。
"Default" のページスタイルオブジェクトのプロパティーを変更するだけでページ設定が変更されます。この "Default" ページスタイルは割り当てているページスタイルを変更していなければ標準のページスタイルです。
"Default" のスタイルは,言語が日本語になっていると "標準" と表示されているものです。
Sub pagestyle_3
Dim oStyleFamilies As Object, oPageStyles As Object
Dim oPageStyle As Object
Dim oDoc As Object, oSheet As Object
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex( 0 )
oStyleFamilies = oDoc.getStyleFamilies()
oPageStyles = oStyleFamilies.getByName( "PageStyles" )
If oPageStyles.hasByName( "Default" ) Then
oPageStyle = oPageStyles.getByName( "Default" )
With oPageStyle
'MsgBox oPageStyle.DisplayName
.BackColor = "&HDDEEFF"
.HeaderOn = false
.FooterOn = false
.PrintCharts = true
End With
End If
End Sub
背景色を変更したり,ヘッダとフッタを印刷しない設定にしています。
ページスタイルの設定項目は多すぎてとても紹介しきれません。ページスタイルのプロパティーをみてください。
用紙サイズと余白 
ページの用紙サイズ設定と余白設定を行ってみます。
用紙サイズ設定 |
SbxLONG Width | 用紙幅 |
SbxLONG Height | 用紙高さ |
余白設定 |
SbxLONG LeftMargin | ページの左余白 |
SbxLONG RightMargin | ページの右余白 |
SbxLONG TopMargin | ページの上余白 |
SbxLONG BottomMargin | ページの下余白 |
上記の表のプロパティーはすべて 1/100 mm 単位で設定します。
その他のプロパティ 
そのほかのページスタイルのプロパティ一覧は ./Properties 参照。
下記はページスタイル編集ダイアログのタブごとに分類したもの。
管理 
プロパティ | 型 | 説明 |
DisplayName | string | スタイルの表示名 |
Name | string | スタイル名 |
ParentStyle | string | 親スタイル名 |
ページ 
プロパティ | 型 | 説明 |
Size | .awt.Size | ページのサイズ |
Width | long | 用紙幅 |
Height | long | 用紙高さ |
IsLandscape | boolean | 用紙方向が横向きかどうか |
LeftMargin | long | ページの左余白 |
RightMargin | long | 右余白 |
TopMargin | long | ページの上余白 |
BottomMargin | long | ページの下余白 |
PrinterPaperTray | string | 印刷用紙トレイ指定 |
PageStyleLayout | .style.PageStyleLayout | ページレイアウト |
NumberingType | short | ページ番号付けの種類 |
CenterHorizontally | boolean | 左右中央よせ |
CenterVertically | boolean | 上下中央よせ |
WritingMode | short | 文字方向 |
UserDefinedAttributes | .container.XNameContainer | ユーザー指定の属性 |
外枠 
プロパティ | 型 | 説明 |
BorderDistance | long | 枠線の間隔 |
LeftBorder | .table.BorderLine | 左枠線 |
LeftBorderDistance | long | 左枠線間隔 |
RightBorder | .table.BorderLine | 右枠線 |
RightBorderDistance | long | 右枠線の間隔 |
TopBorder | .table.BorderLine | 上枠線 |
TopBorderDistance | long | 上枠線間隔 |
BottomBorder | .table.BorderLine | 下側の外枠 |
BottomBorderDistance | long | 下側の外枠線の間隔 |
ShadowFormat | .table.ShadowFormat | 影のフォーマット |
背景 
プロパティ | 型 | 説明 |
BackColor | long | 背景色 |
BackGraphicFilter | string | 背景画像のフィルター名 |
BackGraphicLocation | .style.GraphicLocation | 背景画像の位置 |
BackGraphicURL | string | 背景ファイルの URL |
BackTransparent | boolean | 背景色が透明かどうか |
BackgroundColor | long | 背景色 |
IsBackgroundTransparent | boolean | 背景色を透過させる |
ヘッダー 
プロパティ | 型 | 説明 |
HeaderBackColor | long | ヘッダの背景色 |
HeaderBackGraphicFilter | string | ヘッダの背景画像フィルター名 |
HeaderBackGraphicLocation | .style.GraphicLocation | ヘッダの背景画像配置 |
HeaderBackGraphicURL | string | ヘッダの背景画像 URL |
HeaderBackTransparent | boolean | ヘッダの背景色が透明かどうか |
HeaderBackgroundColor | long | ヘッダの背景色 |
HeaderBodyDistance | long | ヘッダの配置間隔 |
HeaderBorderDistance | long | ヘッダの下枠線 |
HeaderBottomBorder | .table.BorderLine | ヘッダの下枠線 |
HeaderBottomBorderDistance | long | ヘッダ外枠の間隔 |
HeaderDynamic | boolean | ヘッダの間隔を自動調整するかどうか |
HeaderHeight | long | ヘッダの高さ |
HeaderIsDynamicHeight | boolean | ヘッダの高さを自動調節するかどうか |
HeaderIsOn | boolean | ヘッダを付けるかどうか |
HeaderIsShared | boolean | ヘッダを左右同じ内容にするかどうか |
HeaderLeftBorder | .table.BorderLine | ヘッダの左枠線 |
HeaderLeftBorderDistance | long | ヘッダの左枠線間隔 |
HeaderLeftMargin | long | ヘッダの左余白 |
HeaderOn | boolean | ヘッダを付けるかどうか |
HeaderRightBorder | .table.BorderLine | ヘッダの右枠線 |
HeaderRightBorderDistance | long | ヘッダの右枠線間隔 |
HeaderRightMargin | long | ヘッダの右余白 |
HeaderShadowFormat | .table.ShadowFormat | ヘッダの影 |
HeaderShared | boolean | ヘッダを左右同じ内容にするかどうか |
HeaderTopBorder | .table.BorderLine | ヘッダの上枠線 |
HeaderTopBorderDistance | long | ヘッダの上枠線間隔 |
LeftPageHeaderContent | .sheet.XHeaderFooterContent | ヘッダ左側の内容 |
RightPageHeaderContent | .sheet.XHeaderFooterContent | ヘッダ右側の内容 |
TransparentHeaderBackground | boolean | ヘッダの背景を透過する |
フッター 
プロパティ | 型 | 説明 |
FooterBackColor | long | フッタの背景色 |
FooterBackGraphicFilter | string | フッタの背景画像フィルター名 |
FooterBackGraphicLocation | .style.GraphicLocation | フッタの背景画像配置 |
FooterBackGraphicURL | string | フッタの背景画像 URL |
FooterBackTransparent | boolean | フッタの背景色が透明かどうか |
FooterBackgroundColor | long | フッタの背景色 |
FooterBodyDistance | long | フッタの配置間隔 |
FooterBorderDistance | long | フッタ外枠の間隔 |
FooterBottomBorder | .table.BorderLine | フッタの下枠線 |
FooterBottomBorderDistance | long | フッタの下枠線の間隔 |
FooterDynamic | boolean | フッタの高さ |
FooterHeight | long | フッタの高さを自動調節するかどうか |
FooterIsDynamicHeight | boolean | フッタを付けるかどうか |
FooterIsOn | boolean | フッタを左右同じ内容にするかどうか |
FooterIsShared | boolean | フッタを左右同じ内容にするかどうか |
FooterLeftBorder | .table.BorderLine | フッタの左枠線 |
FooterLeftBorderDistance | long | フッタの左枠線間隔 |
FooterLeftMargin | long | フッタの左余白 |
FooterOn | boolean | フッタを付けるかどうか |
FooterRightBorder | .table.BorderLine | フッタの右枠線 |
FooterRightBorderDistance | long | フッタの右枠線間隔 |
FooterRightMargin | long | フッタの右余白 |
FooterShadowFormat | .table.ShadowFormat | フッタの影 |
FooterShared | boolean | フッタを左右同じ内容にするかどうか |
FooterTopBorder | .table.BorderLine | フッタの上枠線 |
FooterTopBorderDistance | long | フッタの上枠線間隔 |
LeftPageFooterContent | .sheet.XHeaderFooterContent | フッタ左側の内容 |
RightPageFooterContent | .sheet.XHeaderFooterContent | フッタ右側の内容 |
TransparentFooterBackground | boolean | フッタの背景を透過する |
シート 
プロパティ | 型 | 説明 |
PrintDownFirst | boolean | 下方向に印刷する |
FirstPageNumber | short | 最初のページ番号 |
PrintAnnotations | boolean | コメントを印刷する |
PrintCharts | boolean | グラフを印刷する |
PrintDrawing | boolean | 図形描写を印刷する |
PrintFormulas | boolean | 数式を印刷する |
PrintGrid | boolean | グリッド線を印刷する |
PrintHeaders | boolean | ヘッダを印刷する |
PrintObjects | boolean | 画像を印刷する |
PrintZeroValues | boolean | ゼロ値を印刷する |
ScaleToPages | short | ページ数に合わせて縮小印刷 |
ScaleToPagesX | short | 横方向のページ数指定 |
ScaleToPagesY | short | 縦方向のページ数指定 |
PageScale | short | 倍率 |