Difference between revisions of "Documentation/BASIC Guide/Formatting Spreadsheet Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Page Margin, Border, and Shadow)
m
 
(29 intermediate revisions by 6 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/BASIC Guide/Editing Spreadsheet Documents
 
|NextPage=Documentation/BASIC Guide/Editing Spreadsheet Documents
 
|spread=block
 
|spread=block
}}<!-- {{DISPLAYTITLE:Formatting Spreadsheet Documents}} -->
+
}}
 
+
{{DISPLAYTITLE:Formatting Spreadsheet Documents}}
 
+
__NOTOC__
= Formatting Spreadsheet Documents =
+
 
+
 
A spreadsheet document provides properties and methods for formatting cells and pages.
 
A spreadsheet document provides properties and methods for formatting cells and pages.
  
 
== Cell Properties ==
 
== Cell Properties ==
  
There are numerous options for formatting cells, such as specifying the font type and size for text. Each cell supports the <tt>com.sun.star.style.CharacterProperties</tt> and <tt>com.sun.star.style.ParagraphProperties</tt> services, the main properties of which are described in '''[[Documentation/BASIC Guide/Text Documents|Text Documents]]'''. Special cell formatting is handled by the <tt>com.sun.star.table.CellProperties</tt> service. The main properties of this service are described in the following sections.
+
There are numerous options for formatting cells, such as specifying the font type and size for text. Each cell supports the <idl>com.sun.star.style.CharacterProperties</idl> and <idl>com.sun.star.style.ParagraphProperties</idl> services, the main properties of which are described in [[Documentation/BASIC Guide/Text Documents|Text Documents]]. Special cell formatting is handled by the <idl>com.sun.star.table.CellProperties</idl> service. The main properties of this service are described in the following sections.
  
 
You can apply all of the named properties to individual cells and to cell ranges.
 
You can apply all of the named properties to individual cells and to cell ranges.
  
 
+
{{Documentation/VBAnote|The <tt>CellProperties</tt> object in the {{AOo}} API is comparable with the <tt>Interior</tt> object from VBA which also defines cell-specific properties.}}
{{Documentation/Note|The <tt>CellProperties</tt> object in the {{OOo}} API is comparable with the <tt>Interior</tt> object from VBA which also defines cell-specific properties.}}
+
  
 
== Background Color and Shadows ==
 
== Background Color and Shadows ==
  
The <tt>com.sun.star.table.CellProperties</tt> service provides the following properties for defining background colors and shadows:
+
The <idl>com.sun.star.table.CellProperties</idl> service provides the following properties for defining background colors and shadows:
  
;<tt>CellBackColor (Long)</tt>:background color of the table cell.
+
;<tt>CellBackColor (Long)</tt>:background color of the table cell
;<tt>IsCellBackgroundTransparent (Boolean)</tt>:sets the background color to transparent.
+
;<tt>IsCellBackgroundTransparent (Boolean)</tt>:sets the background color to transparent
;<tt>ShadowFormat (struct)</tt>:specifies the shadow for cells (structure in accordance with <tt>com.sun.star.table.ShadowFormat</tt> ).
+
;<tt>ShadowFormat (struct)</tt>:specifies the shadow for cells (structure in accordance with <idl>com.sun.star.table.ShadowFormat</idl>)
  
The <tt>com.sun.star.table.ShadowFormat</tt> structure and the detailed specifications for cell shadows have the following structure:
+
The <idl>com.sun.star.table.ShadowFormat</idl> structure and the detailed specifications for cell shadows have the following structure:
  
;<tt>Location (enum)</tt>:position of shadow (value from the <tt>com.sun.star.table.ShadowLocation</tt> structure).
+
;<tt>Location (enum)</tt>:position of shadow (value from the <idl>com.sun.star.table.ShadowLocation</idl> structure).
;<tt>ShadowWidth (Short)</tt>:size of shadow in hundredths of a millimeter.
+
;<tt>ShadowWidth (Short)</tt>:size of shadow in hundredths of a millimeter
;<tt>IsTransparent (Boolean)</tt>:sets the shadow to transparent.
+
;<tt>IsTransparent (Boolean)</tt>:sets the shadow to transparent
;<tt>Color (Long)</tt>:color of shadow.
+
;<tt>Color (Long)</tt>:color of shadow
  
The following example writes the number 1000 to the B2 cell, changes the background color to red using the <tt>CellBackColor</tt> property, and then creates a light gray shadow for the cell that is moved 1 mm to the left and down.
+
The following example writes the number 1000 to the cell B2, changes the background color to red using the <tt>CellBackColor</tt> property, and then creates a light gray shadow for the cell that is moved 1 mm to the left and down.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim Cell As Object
+
Dim Sheet As Object
Dim ShadowFormat As New com.sun.star.table.ShadowFormat
+
Dim Cell As Object
+
Dim ShadowFormat As New com.sun.star.table.ShadowFormat
Doc = StarDesktop.CurrentComponent
+
 
Sheet = Doc.Sheets(0)
+
Doc = ThisComponent
Cell = Sheet.getCellByPosition(1,1)
+
Sheet = Doc.Sheets(0)
+
Cell = Sheet.getCellByPosition(1,1)
Cell.Value = 1000
+
 
+
Cell.Value = 1000
Cell.CellBackColor = RGB(255, 0, 0)
+
 
+
Cell.CellBackColor = RGB(255, 0, 0)
ShadowFormat.Location = com.sun.star.table.ShadowLocation.BOTTOM_RIGHT
+
 
ShadowFormat.ShadowWidth = 100
+
ShadowFormat.Location = com.sun.star.table.ShadowLocation.BOTTOM_RIGHT
ShadowFormat.Color = RGB(160, 160, 160)
+
ShadowFormat.ShadowWidth = 100
+
ShadowFormat.Color = RGB(160, 160, 160)
Cell.ShadowFormat = ShadowFormat
+
 
 +
Cell.ShadowFormat = ShadowFormat
 +
</syntaxhighlight>
  
 
== Justification ==
 
== Justification ==
  
{{OOo}} provides various functions that allow you to change the justification of a text in a table cell.
+
{{AOo}} provides various functions that allow you to change the justification of a text in a table cell.
  
 
The following properties define the horizontal and vertical justification of a text:  
 
The following properties define the horizontal and vertical justification of a text:  
  
;<tt>HoriJustify (enum)</tt>:horizontal justification of the text (value from <tt>com.sun.star.table.CellHoriJustify</tt>)
+
;<tt>HoriJustify (enum)</tt>:horizontal justification of the text (value from <idl>com.sun.star.table.CellHoriJustify</idl>)
;<tt>VertJustify (enum)</tt>:vertical justification of the text (value from <tt>com.sun.star.table.CellVertJustify</tt>)
+
;<tt>VertJustify (enum)</tt>:vertical justification of the text (value from <idl>com.sun.star.table.CellVertJustify</idl>)
;<tt>Orientation (enum)</tt>:orientation of text (value in accordance with <tt>com.sun.star.table.CellOrientation</tt>)
+
;<tt>Orientation (enum)</tt>:orientation of text (value in accordance with <idl>com.sun.star.table.CellOrientation</idl>)
 
;<tt>IsTextWrapped (Boolean)</tt>:permits automatic line breaks within the cell
 
;<tt>IsTextWrapped (Boolean)</tt>:permits automatic line breaks within the cell
 
;<tt>RotateAngle (Long)</tt>:angle of rotation of text in hundredths of a degree
 
;<tt>RotateAngle (Long)</tt>:angle of rotation of text in hundredths of a degree
Line 71: Line 70:
 
The following example shows how you can "stack" the contents of a cell so that the individual characters are printed one under another in the top left corner of the cell. The characters are not rotated.
 
The following example shows how you can "stack" the contents of a cell so that the individual characters are printed one under another in the top left corner of the cell. The characters are not rotated.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim Cell As Object
+
Dim Sheet As Object
+
Dim Cell As Object
Doc = StarDesktop.CurrentComponent
+
 
Sheet = Doc.Sheets(0)
+
Doc = ThisComponent
Cell = Sheet.getCellByPosition(1,1)
+
Sheet = Doc.Sheets(0)
+
Cell = Sheet.getCellByPosition(1,1)
Cell.Value = 1000
+
 
+
Cell.Value = 1000
Cell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
+
 
Cell.VertJustify = com.sun.star.table.CellVertJustify.TOP
+
Cell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
Cell.Orientation = com.sun.star.table.CellOrientation.STACKED
+
Cell.VertJustify = com.sun.star.table.CellVertJustify.TOP
 +
Cell.Orientation = com.sun.star.table.CellOrientation.STACKED
 +
</syntaxhighlight>
  
 
== Number, Date and Text Format ==
 
== Number, Date and Text Format ==
  
{{OOo}} provides a whole range of predefined date and time formats. Each of these formats has an internal number that is used to assign the format to cells using the <tt>NumberFormat</tt> property. {{OOo}} provides the <tt>queryKey</tt> and <tt>addNew</tt> methods so that you can access existing number formats as well as create your own number formats. The methods are accessed through the following object call:
+
{{AOo}} provides a whole range of predefined date and time formats. Each of these formats has an internal number that is used to assign the format to cells using the <tt>NumberFormat</tt> property. {{AOo}} provides the <tt>queryKey</tt> and <tt>addNew</tt> methods so that you can access existing number formats as well as create your own number formats. The methods are accessed through the following object call:
  
NumberFormats = Doc.NumberFormats
+
<syntaxhighlight lang="oobas">
 +
NumberFormats = Doc.NumberFormats
 +
</syntaxhighlight>
  
A format is specified using a format string that is structured in a similar way to the format function of {{OOo}} Basic. However there is one major difference: whereas the command format expects English abbreviations and decimal points or characters as thousands separators, the country-specified abbreviations must be used for the structure of a command format for the <tt>NumberFormats</tt> object.
+
A format is specified using a format string that is structured in a similar way to the format function of {{AOo}} Basic. However there is one major difference: whereas the command format expects English abbreviations and decimal points or characters as thousands separators, the country-specified abbreviations must be used for the structure of a command format for the <tt>NumberFormats</tt> object.
  
 
The following example formats the B2 cell so that numbers are displayed with three decimal places and use commas as a thousands separator.
 
The following example formats the B2 cell so that numbers are displayed with three decimal places and use commas as a thousands separator.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim Cell As Object
+
Dim Sheet As Object
Dim NumberFormats As Object
+
Dim Cell As Object
Dim NumberFormatString As String
+
Dim NumberFormats As Object
Dim NumberFormatId As Long
+
Dim NumberFormatString As String
Dim LocalSettings As New com.sun.star.lang.Locale
+
Dim NumberFormatId As Long
+
Dim LocalSettings As New com.sun.star.lang.Locale
Doc = StarDesktop.CurrentComponent
+
 
Sheet = Doc.Sheets(0)
+
Doc = ThisComponent
Cell = Sheet.getCellByPosition(1,1)
+
Sheet = Doc.Sheets(0)
+
Cell = Sheet.getCellByPosition(1,1)
Cell.Value = 23400.3523565
+
+
LocalSettings.Language = "en"
+
LocalSettings.Country = "us"
+
+
NumberFormats = Doc.NumberFormats
+
NumberFormatString = "#,##0.000"
+
+
NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)
+
If NumberFormatId = -1 Then
+
    NumberFormatId = NumberFormats.addNew(NumberFormatString, LocalSettings)
+
End If
+
+
MsgBox NumberFormatId
+
Cell.NumberFormat = NumberFormatId
+
  
The '''Format Cells''' dialog in {{OOo}} Calc provides an overview of the different formatting options for cells.
+
Cell.Value = 23400.3523565
 +
 
 +
LocalSettings.Language = "en"
 +
LocalSettings.Country = "us"
 +
 
 +
NumberFormats = Doc.NumberFormats
 +
NumberFormatString = "#,##0.000"
 +
 
 +
NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)
 +
If NumberFormatId = -1 Then
 +
  NumberFormatId = NumberFormats.addNew(NumberFormatString, LocalSettings)
 +
End If
 +
 
 +
MsgBox NumberFormatId
 +
Cell.NumberFormat = NumberFormatId
 +
</syntaxhighlight>
 +
 
 +
The '''Format Cells''' dialog in {{AOo}} Calc provides an overview of the different formatting options for cells.
  
 
== Page Properties ==
 
== Page Properties ==
Line 135: Line 140:
 
The procedure for defining page formats differs from other forms of formatting. Whereas cell, paragraph, and character elements can be formatted directly, page formats can also be defined and indirectly applied using page styles. For example, headers or footers are added to the page style.
 
The procedure for defining page formats differs from other forms of formatting. Whereas cell, paragraph, and character elements can be formatted directly, page formats can also be defined and indirectly applied using page styles. For example, headers or footers are added to the page style.
  
The following sections describe the main formatting options for spreadsheet pages. Many of the styles that are described are also available for text documents. The page properties that are valid for both types of documents are defined in the <tt>com.sun.star.style.PageProperties</tt> service. The page properties that only apply to spreadsheet documents are defined in the <tt>com.sun.star.sheet.TablePageStyle</tt> service.
+
The following sections describe the main formatting options for spreadsheet pages. Many of the styles that are described are also available for text documents. The page properties that are valid for both types of documents are defined in the <idl>com.sun.star.style.PageProperties</idl> service. The page properties that only apply to spreadsheet documents are defined in the <idl>com.sun.star.sheet.TablePageStyle</idl> service.
 
+
  
{{Documentation/Note|The page properties (page margins, borders, and so on) for a Microsoft Office document are defined by means of a <tt>PageSetup</tt> object at the <tt>Worksheet</tt> object (Excel) or <tt>Document</tt> object (Word) level. In {{OOo}}, these properties are defined using a page style which in turn is linked to the associated document.}}
+
{{Documentation/VBAnote|The page properties (page margins, borders, and so on) for a Microsoft Office document are defined by means of a <tt>PageSetup</tt> object at the <tt>Worksheet</tt> object (Excel) or <tt>Document</tt> object (Word) level. In {{AOo}}, these properties are defined using a page style which in turn is linked to the associated document.}}
  
 
== Page Background ==
 
== Page Background ==
  
The <tt>com.sun.star.style.PageProperties</tt> service defines the following properties of a pages background:
+
The <idl>com.sun.star.style.PageProperties</idl> service defines the following properties of a pages background:
  
 
;<tt>BackColor (long)</tt>:color of background
 
;<tt>BackColor (long)</tt>:color of background
Line 152: Line 156:
 
== Page Format ==
 
== Page Format ==
  
The page format is defined using the following properties of the <tt>com.sun.star.style.PageProperties</tt> service:
+
The page format is defined using the following properties of the <idl>com.sun.star.style.PageProperties</idl> service:
  
 
;<tt>IsLandscape (Boolean)</tt>:landscape format
 
;<tt>IsLandscape (Boolean)</tt>:landscape format
Line 161: Line 165:
 
The following example sets the page size of the "Default" page style to the DIN A5 landscape format (height 14.8 cm, width 21 cm):
 
The following example sets the page size of the "Default" page style to the DIN A5 landscape format (height 14.8 cm, width 21 cm):
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim StyleFamilies As Object  
+
Dim Sheet As Object
Dim PageStyles As Object
+
Dim StyleFamilies As Object  
Dim DefPage As Object
+
Dim PageStyles As Object
+
Dim DefPage As Object
Doc = StarDesktop.CurrentComponent
+
 
StyleFamilies = Doc.StyleFamilies
+
Doc = ThisComponent
PageStyles = StyleFamilies.getByName("PageStyles")
+
StyleFamilies = Doc.StyleFamilies
DefPage = PageStyles.getByName("Default")
+
PageStyles = StyleFamilies.getByName("PageStyles")
+
DefPage = PageStyles.getByName("Default")
DefPage.IsLandscape = True
+
 
DefPage.Width = 21000
+
DefPage.IsLandscape = True
DefPage.Height = 14800
+
DefPage.Width = 21000
 +
DefPage.Height = 14800
 +
</syntaxhighlight>
  
 
== Page Margin, Border, and Shadow ==
 
== Page Margin, Border, and Shadow ==
  
The <tt>com.sun.star.style.PageProperties</tt> service provides the following properties for adjusting page margins as well as borders and shadows:
+
The <idl>com.sun.star.style.PageProperties</idl> service provides the following properties for adjusting page margins as well as borders and shadows:
  
 
;<tt>LeftMargin (long)</tt>:width of the left hand page margin in hundredths of a millimeter
 
;<tt>LeftMargin (long)</tt>:width of the left hand page margin in hundredths of a millimeter
;<tt>RightMargin (long)</tt>:width of the right hand page margin in hundredths of a millimeter.
+
;<tt>RightMargin (long)</tt>:width of the right hand page margin in hundredths of a millimeter
 
;<tt>TopMargin (long)</tt>:width of the top page margin in hundredths of a millimeter
 
;<tt>TopMargin (long)</tt>:width of the top page margin in hundredths of a millimeter
 
;<tt>BottomMargin (long)</tt>:width of the bottom page margin in hundredths of a millimeter
 
;<tt>BottomMargin (long)</tt>:width of the bottom page margin in hundredths of a millimeter
;<tt>LeftBorder (struct)</tt>:specifications for left-hand line of page border <tt>(com.sun.star.table.BorderLine</tt> structure)
+
;<tt>LeftBorder (struct)</tt>:specifications for left-hand line of page border (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>RightBorder (struct)</tt>:specifications for right-hand line of page border (<tt>(com.sun.star.table.BorderLine</tt> structure)
+
;<tt>RightBorder (struct)</tt>:specifications for right-hand line of page border (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>TopBorder (struct)</tt>:specifications for top line of page border (<tt>(com.sun.star.table.BorderLine</tt> structure)
+
;<tt>TopBorder (struct)</tt>:specifications for top line of page border (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>BottomBorder (struct)</tt>:specifications for bottom line of page border (<tt>(com.sun.star.table.BorderLine</tt> structure)
+
;<tt>BottomBorder (struct)</tt>:specifications for bottom line of page border (<idl>com.sun.star.table.BorderLine</idl> structure)
 
;<tt>LeftBorderDistance (long)</tt>:distance between left-hand page border and page content in hundredths of a millimeter
 
;<tt>LeftBorderDistance (long)</tt>:distance between left-hand page border and page content in hundredths of a millimeter
 
;<tt>RightBorderDistance (long)</tt>:distance between right-hand page border and page content in hundredths of a millimeter
 
;<tt>RightBorderDistance (long)</tt>:distance between right-hand page border and page content in hundredths of a millimeter
 
;<tt>TopBorderDistance (long)</tt>:distance between top page border and page content in hundredths of a millimeter
 
;<tt>TopBorderDistance (long)</tt>:distance between top page border and page content in hundredths of a millimeter
 
;<tt>BottomBorderDistance (long)</tt>:distance between bottom page border and page content in hundredths of a millimeter
 
;<tt>BottomBorderDistance (long)</tt>:distance between bottom page border and page content in hundredths of a millimeter
;<tt>ShadowFormat (struct)</tt>:specifications for shadow of content area of page (<tt>(com.sun.star.table.ShadowFormat</tt> structure)
+
;<tt>ShadowFormat (struct)</tt>:specifications for shadow of content area of page (<idl>com.sun.star.table.ShadowFormat</idl> structure)
  
 
The following example sets the left and right-hand borders of the "Default" page style to 1 centimeter.
 
The following example sets the left and right-hand borders of the "Default" page style to 1 centimeter.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim StyleFamilies As Object  
+
Dim Sheet As Object
Dim PageStyles As Object
+
Dim StyleFamilies As Object  
Dim DefPage As Object
+
Dim PageStyles As Object
+
Dim DefPage As Object
Doc = StarDesktop.CurrentComponent
+
 
StyleFamilies = Doc.StyleFamilies
+
Doc = ThisComponent
PageStyles = StyleFamilies.getByName("PageStyles")
+
StyleFamilies = Doc.StyleFamilies
DefPage = PageStyles.getByName("Default")
+
PageStyles = StyleFamilies.getByName("PageStyles")
+
DefPage = PageStyles.getByName("Default")
DefPage.LeftMargin = 1000
+
 
DefPage.RightMargin = 1000
+
DefPage.LeftMargin = 1000
 +
DefPage.RightMargin = 1000
 +
</syntaxhighlight>
  
 
== Headers and Footers ==
 
== Headers and Footers ==
  
The headers and footers of a document form part of the page properties and are defined using the <tt>com.sun.star.style.PageProperties</tt> service. The properties for formatting headers are:
+
The headers and footers of a document form part of the page properties and are defined using the <idl>com.sun.star.style.PageProperties</idl> service. The properties for formatting headers are:
  
 
;<tt>HeaderIsOn (Boolean)</tt>:header is activated
 
;<tt>HeaderIsOn (Boolean)</tt>:header is activated
;<tt>HeaderLeftMargin (long)</tt>:distance between header and left-hand page margin in hundredths of a millimeter.
+
;<tt>HeaderLeftMargin (long)</tt>:distance between header and left-hand page margin in hundredths of a millimeter
 
;<tt>HeaderRightMargin (long)</tt>:distance between header and right-hand page margin in hundredths of a millimeter
 
;<tt>HeaderRightMargin (long)</tt>:distance between header and right-hand page margin in hundredths of a millimeter
 
;<tt>HeaderBodyDistance (long)</tt>:distance between header and main body of document in hundredths of a millimeter
 
;<tt>HeaderBodyDistance (long)</tt>:distance between header and main body of document in hundredths of a millimeter
 
;<tt>HeaderHeight (long)</tt>:height of header in hundredths of a millimeter
 
;<tt>HeaderHeight (long)</tt>:height of header in hundredths of a millimeter
 
;<tt>HeaderIsDynamicHeight (Boolean)</tt>:height of header is automatically adapted to content
 
;<tt>HeaderIsDynamicHeight (Boolean)</tt>:height of header is automatically adapted to content
;<tt>HeaderLeftBorder (struct)</tt>:details of the left-hand border of frame around header (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>HeaderLeftBorder (struct)</tt>:details of the left-hand border of frame around header (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>HeaderRightBorder (struct)</tt>:details of the right-hand border of frame around header (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>HeaderRightBorder (struct)</tt>:details of the right-hand border of frame around header (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>HeaderTopBorder (struct)</tt>:details of the top line of the border around header (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>HeaderTopBorder (struct)</tt>:details of the top line of the border around header (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>HeaderBottomBorder (struct)</tt>:details of the bottom line of the border around header (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>HeaderBottomBorder (struct)</tt>:details of the bottom line of the border around header (<idl>com.sun.star.table.BorderLine</idl> structure)
 
;<tt>HeaderLeftBorderDistance (long)</tt>:distance between left-hand border and content of header in hundredths of a millimeter
 
;<tt>HeaderLeftBorderDistance (long)</tt>:distance between left-hand border and content of header in hundredths of a millimeter
 
;<tt>HeaderRightBorderDistance (long)</tt>:distance between right-hand border and content of header in hundredths of a millimeter
 
;<tt>HeaderRightBorderDistance (long)</tt>:distance between right-hand border and content of header in hundredths of a millimeter
Line 232: Line 240:
 
;<tt>HeaderBackGraphicURL (String)</tt>:URL of the background graphics that you want to use
 
;<tt>HeaderBackGraphicURL (String)</tt>:URL of the background graphics that you want to use
 
;<tt>HeaderBackGraphicFilter (String)</tt>:name of the filter for interpreting the background graphics for the header
 
;<tt>HeaderBackGraphicFilter (String)</tt>:name of the filter for interpreting the background graphics for the header
;<tt>HeaderBackGraphicLocation (Enum)</tt>:position of the background graphics for the header (value according to <tt>com.sun.star.style.GraphicLocation</tt> enumeration)
+
;<tt>HeaderBackGraphicLocation (Enum)</tt>:position of the background graphics for the header (value according to <idl>com.sun.star.style.GraphicLocation</idl> enumeration)
 
;<tt>HeaderBackTransparent (Boolean)</tt>:shows the background of the header as transparent
 
;<tt>HeaderBackTransparent (Boolean)</tt>:shows the background of the header as transparent
;<tt>HeaderShadowFormat (struct)</tt>:details of shadow of header (<tt>com.sun.star.table.ShadowFormat</tt> structure)
+
;<tt>HeaderShadowFormat (struct)</tt>:details of shadow of header (<idl>com.sun.star.table.ShadowFormat</idl> structure)
  
 
The properties for formatting footers are:
 
The properties for formatting footers are:
Line 244: Line 252:
 
;<tt>FooterHeight (long)</tt>:height of footer in hundredths of a millimeter
 
;<tt>FooterHeight (long)</tt>:height of footer in hundredths of a millimeter
 
;<tt>FooterIsDynamicHeight (Boolean)</tt>:height of footer is adapted automatically to the content
 
;<tt>FooterIsDynamicHeight (Boolean)</tt>:height of footer is adapted automatically to the content
;<tt>FooterLeftBorder (struct)</tt>:details of left-hand line of border around footer (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>FooterLeftBorder (struct)</tt>:details of left-hand line of border around footer (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>FooterRightBorder (struct)</tt>:details of right-hand line of border around footer (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>FooterRightBorder (struct)</tt>:details of right-hand line of border around footer (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>FooterTopBorder (struct)</tt>:details of top line of border around footer (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>FooterTopBorder (struct)</tt>:details of top line of border around footer (<idl>com.sun.star.table.BorderLine</idl> structure)
;<tt>FooterBottomBorder (struct)</tt>:details of bottom line of border around footer (<tt>com.sun.star.table.BorderLine</tt> structure)
+
;<tt>FooterBottomBorder (struct)</tt>:details of bottom line of border around footer (<idl>com.sun.star.table.BorderLine</idl> structure)
 
;<tt>FooterLeftBorderDistance (long)</tt>:distance between left-hand border and content of footer in hundredths of a millimeter
 
;<tt>FooterLeftBorderDistance (long)</tt>:distance between left-hand border and content of footer in hundredths of a millimeter
 
;<tt>FooterRightBorderDistance (long)</tt>:distance between right-hand border and content of footer in hundredths of a millimeter
 
;<tt>FooterRightBorderDistance (long)</tt>:distance between right-hand border and content of footer in hundredths of a millimeter
 
;<tt>FooterTopBorderDistance (long)</tt>:distance between top border and content of footer in hundredths of a millimeter
 
;<tt>FooterTopBorderDistance (long)</tt>:distance between top border and content of footer in hundredths of a millimeter
 
;<tt>FooterBottomBorderDistance (long)</tt>:distance between bottom border and content of footer in hundredths of a millimeter
 
;<tt>FooterBottomBorderDistance (long)</tt>:distance between bottom border and content of footer in hundredths of a millimeter
;<tt>FooterIsShared (Boolean)</tt>:the footers on the even and odd pages have the same content (refer to <tt>FooterText</tt>, <tt>FooterTextLeft</tt>, and <tt>FooterTextRight</tt> ).
+
;<tt>FooterIsShared (Boolean)</tt>:the footers on the even and odd pages have the same content (refer to <tt>FooterText</tt>, <tt>FooterTextLeft</tt>, and <tt>FooterTextRight</tt> )
 
;<tt>FooterBackColor (long)</tt>:background color of footer
 
;<tt>FooterBackColor (long)</tt>:background color of footer
 
;<tt>FooterBackGraphicURL (String)</tt>:URL of the background graphics that you want to use
 
;<tt>FooterBackGraphicURL (String)</tt>:URL of the background graphics that you want to use
 
;<tt>FooterBackGraphicFilter (String)</tt>:name of the filter for interpreting the background graphics for the footer
 
;<tt>FooterBackGraphicFilter (String)</tt>:name of the filter for interpreting the background graphics for the footer
;<tt>FooterBackGraphicLocation (Enum)</tt>:position of background graphics for the footer (value according to <tt>com.sun.star.style.GraphicLocation</tt> enumeration)
+
;<tt>FooterBackGraphicLocation (Enum)</tt>:position of background graphics for the footer (value according to <idl>com.sun.star.style.GraphicLocation</idl> enumeration)
 
;<tt>FooterBackTransparent (Boolean) </tt>:shows the background of the footer as transparent
 
;<tt>FooterBackTransparent (Boolean) </tt>:shows the background of the footer as transparent
;<tt>FooterShadowFormat (struct)</tt>:details of shadow of footer (<tt>com.sun.star.table.ShadowFormat</tt> structure)
+
;<tt>FooterShadowFormat (struct)</tt>:details of shadow of footer (<idl>com.sun.star.table.ShadowFormat</idl> structure)
  
 
== Changing the Text of Headers and Footers ==
 
== Changing the Text of Headers and Footers ==
Line 264: Line 272:
 
The content of headers and footers in a spreadsheet is accessed through the following properties:
 
The content of headers and footers in a spreadsheet is accessed through the following properties:
  
;<tt>LeftPageHeaderContent (Object)</tt>:content of headers for even pages (<tt>com.sun.star.sheet.HeaderFooterContent</tt> service)
+
;<tt>LeftPageHeaderContent (Object)</tt>:content of headers for even pages (<idl>com.sun.star.sheet.HeaderFooterContent</idl> service)
;<tt>RightPageHeaderContent (Object)</tt>:content of headers for odd pages (<tt>com.sun.star.sheet.HeaderFooterContent</tt> service)
+
;<tt>RightPageHeaderContent (Object)</tt>:content of headers for odd pages (<idl>com.sun.star.sheet.HeaderFooterContent</idl> service)
;<tt>LeftPageFooterContent (Object)</tt>:content of footers for even pages (<tt>com.sun.star.sheet.HeaderFooterContent</tt> service)
+
;<tt>LeftPageFooterContent (Object)</tt>:content of footers for even pages (<idl>com.sun.star.sheet.HeaderFooterContent</idl> service)
;<tt>RightPageFooterContent (Object)</tt>:content of footers for odd pages (<tt>com.sun.star.sheet.HeaderFooterContent</tt> service)
+
;<tt>RightPageFooterContent (Object)</tt>:content of footers for odd pages (<idl>com.sun.star.sheet.HeaderFooterContent</idl> service)
  
 
If you do not need to distinguish between headers or footers for odd and even pages (the <tt>FooterIsShared</tt> property is <tt>False</tt>), then set the properties for headers and footers on odd pages.
 
If you do not need to distinguish between headers or footers for odd and even pages (the <tt>FooterIsShared</tt> property is <tt>False</tt>), then set the properties for headers and footers on odd pages.
  
All the named objects return an object that supports the <tt>com.sun.star.sheet.HeaderFooterContent</tt> service. By means of the (non-genuine) properties <tt>LeftText</tt>, <tt>CenterText</tt>, and <tt>RightText</tt>, this service provides three text elements for the headers and footers of {{OOo}} Calc.
+
All the named objects return an object that supports the <idl>com.sun.star.sheet.HeaderFooterContent</idl> service. By means of the (non-genuine) properties <tt>LeftText</tt>, <tt>CenterText</tt>, and <tt>RightText</tt>, this service provides three text elements for the headers and footers of {{AOo}} Calc.
  
 
The following example writes the "Just a Test." value in the left-hand text field of the header from the "Default" template.
 
The following example writes the "Just a Test." value in the left-hand text field of the header from the "Default" template.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim StyleFamilies As Object  
+
Dim Sheet As Object
Dim PageStyles As Object
+
Dim StyleFamilies As Object  
Dim DefPage As Object
+
Dim PageStyles As Object
Dim HText As Object
+
Dim DefPage As Object
Dim HContent As Object
+
Dim HText As Object
Doc = StarDesktop.CurrentComponent
+
Dim HContent As Object
StyleFamilies = Doc.StyleFamilies
+
Doc = ThisComponent
PageStyles = StyleFamilies.getByName("PageStyles")
+
StyleFamilies = Doc.StyleFamilies
DefPage = PageStyles.getByName("Default")
+
PageStyles = StyleFamilies.getByName("PageStyles")
 
+
DefPage = PageStyles.getByName("Default")
DefPage.HeaderIsOn = True
+
HContent = DefPage.RightPageHeaderContent
+
DefPage.HeaderIsOn = True
HText = HContent.LeftText
+
HContent = DefPage.RightPageHeaderContent
HText.String = "Just a Test."
+
HText = HContent.LeftText
DefPage.RightPageHeaderContent = HContent
+
HText.String = "Just a Test."
 +
DefPage.RightPageHeaderContent = HContent
 +
</syntaxhighlight>
  
 
Note the last line in the example: Once the text is changed, the <tt>TextContent</tt> object must be assigned to the header again so that the change is effective.
 
Note the last line in the example: Once the text is changed, the <tt>TextContent</tt> object must be assigned to the header again so that the change is effective.
  
Another mechanism for changing the text of headers and footers is available for text documents ({{OOo}} Writer) because these consist of a single block of text. The following properties are defined in the <tt>com.sun.star.style.PageProperties</tt> service:
+
Another mechanism for changing the text of headers and footers is available for text documents ({{AOo}} Writer) because these consist of a single block of text. The following properties are defined in the <idl>com.sun.star.style.PageProperties</idl> service:
  
;<tt>HeaderText (Object) </tt>:text object with content of the header (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>HeaderText (Object) </tt>:text object with content of the header (<idl>com.sun.star.text.XText</idl> service)
;<tt>HeaderTextLeft (Object)</tt>:text object with content of headers on left-hand pages (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>HeaderTextLeft (Object)</tt>:text object with content of headers on left-hand pages (<idl>com.sun.star.text.XText</idl> service)
;<tt>HeaderTextRight (Object)</tt>:text object with content of headers on right-hand pages (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>HeaderTextRight (Object)</tt>:text object with content of headers on right-hand pages (<idl>com.sun.star.text.XText</idl> service)
;<tt>FooterText (Object)</tt>:text object with content of the footer (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>FooterText (Object)</tt>:text object with content of the footer (<idl>com.sun.star.text.XText</idl> service)
;<tt>FooterTextLeft (Object)</tt>:text object with content of footers on left-hand pages (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>FooterTextLeft (Object)</tt>:text object with content of footers on left-hand pages (<idl>com.sun.star.text.XText</idl> service)
;<tt>FooterTextRight (Object)</tt>:text object with content of footers on right-hand pages (<tt>com.sun.star.text.XText</tt> service)
+
;<tt>FooterTextRight (Object)</tt>:text object with content of footers on right-hand pages (<idl>com.sun.star.text.XText</idl> service)
  
 
The following example creates a header in the "Default" page style for text documents and adds the text "Just a Test" to the header.
 
The following example creates a header in the "Default" page style for text documents and adds the text "Just a Test" to the header.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Sheet As Object
+
Dim Doc As Object
Dim StyleFamilies As Object  
+
Dim Sheet As Object
Dim PageStyles As Object
+
Dim StyleFamilies As Object  
Dim DefPage As Object
+
Dim PageStyles As Object
Dim HText As Object
+
Dim DefPage As Object
 +
Dim HText As Object
  
Doc = StarDesktop.CurrentComponent
+
Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
+
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
+
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("Default")
+
DefPage = PageStyles.getByName("Default")
  
DefPage.HeaderIsOn = True
+
DefPage.HeaderIsOn = True
HText = DefPage.HeaderText  
+
HText = DefPage.HeaderText  
  
HText.String = "Just a Test."
+
HText.String = "Just a Test."
 +
</syntaxhighlight>
  
 
In this instance, access is provided directly through the <tt>HeaderText</tt> property of the page style rather than the <tt>HeaderFooterContent</tt> object.
 
In this instance, access is provided directly through the <tt>HeaderText</tt> property of the page style rather than the <tt>HeaderFooterContent</tt> object.
Line 327: Line 339:
 
== Centering (Spreadsheets Only) ==
 
== Centering (Spreadsheets Only) ==
  
The <tt>com.sun.star.sheet.TablePageStyle</tt> service is only used in {{OOo}} Calc page styles and allows cell ranges that you want to printed to be centered on the page. This service provides the following properties:
+
The <idl>com.sun.star.sheet.TablePageStyle</idl> service is only used in {{AOo}} Calc page styles and allows cell ranges that you want printed to be centered on the page. This service provides the following properties:
  
 
;<tt>CenterHorizontally (Boolean)</tt>:table content is centered horizontally
 
;<tt>CenterHorizontally (Boolean)</tt>:table content is centered horizontally
Line 334: Line 346:
 
== Definition of Elements to be Printed (Spreadsheets Only) ==
 
== Definition of Elements to be Printed (Spreadsheets Only) ==
  
When you format sheets, you can define whether page elements are visible. For this purpose, the <tt>com.sun.star.sheet.TablePageStyle</tt> service provides the following properties:  
+
When you format sheets, you can define whether page elements are visible. For this purpose, the <idl>com.sun.star.sheet.TablePageStyle</idl> service provides the following properties:  
  
 
;<tt>PrintAnnotations (Boolean)</tt>:prints cell comments
 
;<tt>PrintAnnotations (Boolean)</tt>:prints cell comments
Line 346: Line 358:
 
;<tt>PrintZeroValues (Boolean)</tt>:prints the zero values
 
;<tt>PrintZeroValues (Boolean)</tt>:prints the zero values
  
 +
 +
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Formatting Spreadsheet Documents}}
 
{{PDL1}}
 
{{PDL1}}

Latest revision as of 13:30, 30 January 2021


A spreadsheet document provides properties and methods for formatting cells and pages.

Cell Properties

There are numerous options for formatting cells, such as specifying the font type and size for text. Each cell supports the com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties services, the main properties of which are described in Text Documents. Special cell formatting is handled by the com.sun.star.table.CellProperties service. The main properties of this service are described in the following sections.

You can apply all of the named properties to individual cells and to cell ranges.

Documentation note.png VBA : The CellProperties object in the Apache OpenOffice API is comparable with the Interior object from VBA which also defines cell-specific properties.


Background Color and Shadows

The com.sun.star.table.CellProperties service provides the following properties for defining background colors and shadows:

CellBackColor (Long)
background color of the table cell
IsCellBackgroundTransparent (Boolean)
sets the background color to transparent
ShadowFormat (struct)
specifies the shadow for cells (structure in accordance with com.sun.star.table.ShadowFormat)

The com.sun.star.table.ShadowFormat structure and the detailed specifications for cell shadows have the following structure:

Location (enum)
position of shadow (value from the com.sun.star.table.ShadowLocation structure).
ShadowWidth (Short)
size of shadow in hundredths of a millimeter
IsTransparent (Boolean)
sets the shadow to transparent
Color (Long)
color of shadow

The following example writes the number 1000 to the cell B2, changes the background color to red using the CellBackColor property, and then creates a light gray shadow for the cell that is moved 1 mm to the left and down.

Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
Dim ShadowFormat As New com.sun.star.table.ShadowFormat
 
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(1,1)
 
Cell.Value = 1000
 
Cell.CellBackColor = RGB(255, 0, 0)
 
ShadowFormat.Location = com.sun.star.table.ShadowLocation.BOTTOM_RIGHT
ShadowFormat.ShadowWidth = 100
ShadowFormat.Color = RGB(160, 160, 160)
 
Cell.ShadowFormat = ShadowFormat

Justification

Apache OpenOffice provides various functions that allow you to change the justification of a text in a table cell.

The following properties define the horizontal and vertical justification of a text:

HoriJustify (enum)
horizontal justification of the text (value from com.sun.star.table.CellHoriJustify)
VertJustify (enum)
vertical justification of the text (value from com.sun.star.table.CellVertJustify)
Orientation (enum)
orientation of text (value in accordance with com.sun.star.table.CellOrientation)
IsTextWrapped (Boolean)
permits automatic line breaks within the cell
RotateAngle (Long)
angle of rotation of text in hundredths of a degree

The following example shows how you can "stack" the contents of a cell so that the individual characters are printed one under another in the top left corner of the cell. The characters are not rotated.

Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
 
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(1,1)
 
Cell.Value = 1000
 
Cell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
Cell.VertJustify = com.sun.star.table.CellVertJustify.TOP
Cell.Orientation = com.sun.star.table.CellOrientation.STACKED

Number, Date and Text Format

Apache OpenOffice provides a whole range of predefined date and time formats. Each of these formats has an internal number that is used to assign the format to cells using the NumberFormat property. Apache OpenOffice provides the queryKey and addNew methods so that you can access existing number formats as well as create your own number formats. The methods are accessed through the following object call:

NumberFormats = Doc.NumberFormats

A format is specified using a format string that is structured in a similar way to the format function of Apache OpenOffice Basic. However there is one major difference: whereas the command format expects English abbreviations and decimal points or characters as thousands separators, the country-specified abbreviations must be used for the structure of a command format for the NumberFormats object.

The following example formats the B2 cell so that numbers are displayed with three decimal places and use commas as a thousands separator.

Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
Dim NumberFormats As Object
Dim NumberFormatString As String
Dim NumberFormatId As Long
Dim LocalSettings As New com.sun.star.lang.Locale
 
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(1,1)
 
Cell.Value = 23400.3523565
 
LocalSettings.Language = "en"
LocalSettings.Country = "us"
 
NumberFormats = Doc.NumberFormats
NumberFormatString = "#,##0.000"
 
NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)
If NumberFormatId = -1 Then
   NumberFormatId = NumberFormats.addNew(NumberFormatString, LocalSettings)
End If
 
MsgBox NumberFormatId
Cell.NumberFormat = NumberFormatId

The Format Cells dialog in Apache OpenOffice Calc provides an overview of the different formatting options for cells.

Page Properties

Page properties are the formatting options that position document content on a page as well as visual elements that are repeated page after page. These include

  • Paper formats
  • Page margins
  • Headers and footers.

The procedure for defining page formats differs from other forms of formatting. Whereas cell, paragraph, and character elements can be formatted directly, page formats can also be defined and indirectly applied using page styles. For example, headers or footers are added to the page style.

The following sections describe the main formatting options for spreadsheet pages. Many of the styles that are described are also available for text documents. The page properties that are valid for both types of documents are defined in the com.sun.star.style.PageProperties service. The page properties that only apply to spreadsheet documents are defined in the com.sun.star.sheet.TablePageStyle service.

Documentation note.png VBA : The page properties (page margins, borders, and so on) for a Microsoft Office document are defined by means of a PageSetup object at the Worksheet object (Excel) or Document object (Word) level. In Apache OpenOffice, these properties are defined using a page style which in turn is linked to the associated document.


Page Background

The com.sun.star.style.PageProperties service defines the following properties of a pages background:

BackColor (long)
color of background
BackGraphicURL (String)
URL of the background graphics that you want to use
BackGraphicFilter (String)
name of the filter for interpreting the background graphics
BackGraphicLocation (Enum)
position of the background graphics (value according to enumeration)
BackTransparent (Boolean)
makes the background transparent

Page Format

The page format is defined using the following properties of the com.sun.star.style.PageProperties service:

IsLandscape (Boolean)
landscape format
Width (long)
width of page in hundredths of a millimeter
Height (long)
height of page in hundredths of a millimeter
PrinterPaperTray (String)
name of the printer paper tray that you want to use

The following example sets the page size of the "Default" page style to the DIN A5 landscape format (height 14.8 cm, width 21 cm):

Dim Doc As Object
Dim Sheet As Object
Dim StyleFamilies As Object 
Dim PageStyles As Object
Dim DefPage As Object
 
Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("Default")
 
DefPage.IsLandscape = True
DefPage.Width = 21000
DefPage.Height = 14800

Page Margin, Border, and Shadow

The com.sun.star.style.PageProperties service provides the following properties for adjusting page margins as well as borders and shadows:

LeftMargin (long)
width of the left hand page margin in hundredths of a millimeter
RightMargin (long)
width of the right hand page margin in hundredths of a millimeter
TopMargin (long)
width of the top page margin in hundredths of a millimeter
BottomMargin (long)
width of the bottom page margin in hundredths of a millimeter
LeftBorder (struct)
specifications for left-hand line of page border (com.sun.star.table.BorderLine structure)
RightBorder (struct)
specifications for right-hand line of page border (com.sun.star.table.BorderLine structure)
TopBorder (struct)
specifications for top line of page border (com.sun.star.table.BorderLine structure)
BottomBorder (struct)
specifications for bottom line of page border (com.sun.star.table.BorderLine structure)
LeftBorderDistance (long)
distance between left-hand page border and page content in hundredths of a millimeter
RightBorderDistance (long)
distance between right-hand page border and page content in hundredths of a millimeter
TopBorderDistance (long)
distance between top page border and page content in hundredths of a millimeter
BottomBorderDistance (long)
distance between bottom page border and page content in hundredths of a millimeter
ShadowFormat (struct)
specifications for shadow of content area of page (com.sun.star.table.ShadowFormat structure)

The following example sets the left and right-hand borders of the "Default" page style to 1 centimeter.

Dim Doc As Object
Dim Sheet As Object
Dim StyleFamilies As Object 
Dim PageStyles As Object
Dim DefPage As Object
 
Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("Default")
 
DefPage.LeftMargin = 1000
DefPage.RightMargin = 1000

Headers and Footers

The headers and footers of a document form part of the page properties and are defined using the com.sun.star.style.PageProperties service. The properties for formatting headers are:

HeaderIsOn (Boolean)
header is activated
HeaderLeftMargin (long)
distance between header and left-hand page margin in hundredths of a millimeter
HeaderRightMargin (long)
distance between header and right-hand page margin in hundredths of a millimeter
HeaderBodyDistance (long)
distance between header and main body of document in hundredths of a millimeter
HeaderHeight (long)
height of header in hundredths of a millimeter
HeaderIsDynamicHeight (Boolean)
height of header is automatically adapted to content
HeaderLeftBorder (struct)
details of the left-hand border of frame around header (com.sun.star.table.BorderLine structure)
HeaderRightBorder (struct)
details of the right-hand border of frame around header (com.sun.star.table.BorderLine structure)
HeaderTopBorder (struct)
details of the top line of the border around header (com.sun.star.table.BorderLine structure)
HeaderBottomBorder (struct)
details of the bottom line of the border around header (com.sun.star.table.BorderLine structure)
HeaderLeftBorderDistance (long)
distance between left-hand border and content of header in hundredths of a millimeter
HeaderRightBorderDistance (long)
distance between right-hand border and content of header in hundredths of a millimeter
HeaderTopBorderDistance (long)
distance between top border and content of header in hundredths of a millimeter
HeaderBottomBorderDistance (long)
distance between bottom border and content of header in hundredths of a millimeter
HeaderIsShared (Boolean)
headers on even and odd pages have the same content (refer to HeaderText , HeaderTextLeft, and HeaderTextRight )
HeaderBackColor (long)
background color of header
HeaderBackGraphicURL (String)
URL of the background graphics that you want to use
HeaderBackGraphicFilter (String)
name of the filter for interpreting the background graphics for the header
HeaderBackGraphicLocation (Enum)
position of the background graphics for the header (value according to com.sun.star.style.GraphicLocation enumeration)
HeaderBackTransparent (Boolean)
shows the background of the header as transparent
HeaderShadowFormat (struct)
details of shadow of header (com.sun.star.table.ShadowFormat structure)

The properties for formatting footers are:

FooterIsOn (Boolean)
footer is activated
FooterLeftMargin (long)
distance between footer and left-hand page margin in hundredths of a millimeter
FooterRightMargin (long)
distance between footer and right-hand page margin in hundredths of a millimeter
FooterBodyDistance (long)
distance between footer and main body of document in hundredths of a millimeter
FooterHeight (long)
height of footer in hundredths of a millimeter
FooterIsDynamicHeight (Boolean)
height of footer is adapted automatically to the content
FooterLeftBorder (struct)
details of left-hand line of border around footer (com.sun.star.table.BorderLine structure)
FooterRightBorder (struct)
details of right-hand line of border around footer (com.sun.star.table.BorderLine structure)
FooterTopBorder (struct)
details of top line of border around footer (com.sun.star.table.BorderLine structure)
FooterBottomBorder (struct)
details of bottom line of border around footer (com.sun.star.table.BorderLine structure)
FooterLeftBorderDistance (long)
distance between left-hand border and content of footer in hundredths of a millimeter
FooterRightBorderDistance (long)
distance between right-hand border and content of footer in hundredths of a millimeter
FooterTopBorderDistance (long)
distance between top border and content of footer in hundredths of a millimeter
FooterBottomBorderDistance (long)
distance between bottom border and content of footer in hundredths of a millimeter
FooterIsShared (Boolean)
the footers on the even and odd pages have the same content (refer to FooterText, FooterTextLeft, and FooterTextRight )
FooterBackColor (long)
background color of footer
FooterBackGraphicURL (String)
URL of the background graphics that you want to use
FooterBackGraphicFilter (String)
name of the filter for interpreting the background graphics for the footer
FooterBackGraphicLocation (Enum)
position of background graphics for the footer (value according to com.sun.star.style.GraphicLocation enumeration)
FooterBackTransparent (Boolean)
shows the background of the footer as transparent
FooterShadowFormat (struct)
details of shadow of footer (com.sun.star.table.ShadowFormat structure)

Changing the Text of Headers and Footers

The content of headers and footers in a spreadsheet is accessed through the following properties:

LeftPageHeaderContent (Object)
content of headers for even pages (com.sun.star.sheet.HeaderFooterContent service)
RightPageHeaderContent (Object)
content of headers for odd pages (com.sun.star.sheet.HeaderFooterContent service)
LeftPageFooterContent (Object)
content of footers for even pages (com.sun.star.sheet.HeaderFooterContent service)
RightPageFooterContent (Object)
content of footers for odd pages (com.sun.star.sheet.HeaderFooterContent service)

If you do not need to distinguish between headers or footers for odd and even pages (the FooterIsShared property is False), then set the properties for headers and footers on odd pages.

All the named objects return an object that supports the com.sun.star.sheet.HeaderFooterContent service. By means of the (non-genuine) properties LeftText, CenterText, and RightText, this service provides three text elements for the headers and footers of Apache OpenOffice Calc.

The following example writes the "Just a Test." value in the left-hand text field of the header from the "Default" template.

Dim Doc As Object
Dim Sheet As Object
Dim StyleFamilies As Object 
Dim PageStyles As Object
Dim DefPage As Object
Dim HText As Object
Dim HContent As Object
Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("Default")
 
DefPage.HeaderIsOn = True
HContent = DefPage.RightPageHeaderContent
HText = HContent.LeftText
HText.String = "Just a Test."
DefPage.RightPageHeaderContent = HContent

Note the last line in the example: Once the text is changed, the TextContent object must be assigned to the header again so that the change is effective.

Another mechanism for changing the text of headers and footers is available for text documents (Apache OpenOffice Writer) because these consist of a single block of text. The following properties are defined in the com.sun.star.style.PageProperties service:

HeaderText (Object)
text object with content of the header (com.sun.star.text.XText service)
HeaderTextLeft (Object)
text object with content of headers on left-hand pages (com.sun.star.text.XText service)
HeaderTextRight (Object)
text object with content of headers on right-hand pages (com.sun.star.text.XText service)
FooterText (Object)
text object with content of the footer (com.sun.star.text.XText service)
FooterTextLeft (Object)
text object with content of footers on left-hand pages (com.sun.star.text.XText service)
FooterTextRight (Object)
text object with content of footers on right-hand pages (com.sun.star.text.XText service)

The following example creates a header in the "Default" page style for text documents and adds the text "Just a Test" to the header.

Dim Doc As Object
Dim Sheet As Object
Dim StyleFamilies As Object 
Dim PageStyles As Object
Dim DefPage As Object
Dim HText As Object
 
Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("Default")
 
DefPage.HeaderIsOn = True
HText = DefPage.HeaderText 
 
HText.String = "Just a Test."

In this instance, access is provided directly through the HeaderText property of the page style rather than the HeaderFooterContent object.

Centering (Spreadsheets Only)

The com.sun.star.sheet.TablePageStyle service is only used in Apache OpenOffice Calc page styles and allows cell ranges that you want printed to be centered on the page. This service provides the following properties:

CenterHorizontally (Boolean)
table content is centered horizontally
CenterVertically (Boolean)
table content is centered vertically

Definition of Elements to be Printed (Spreadsheets Only)

When you format sheets, you can define whether page elements are visible. For this purpose, the com.sun.star.sheet.TablePageStyle service provides the following properties:

PrintAnnotations (Boolean)
prints cell comments
PrintGrid (Boolean)
prints the cell gridlines
PrintHeaders (Boolean)
prints the row and column headings
PrintCharts (Boolean)
prints charts contained in a sheet
PrintObjects (Boolean)
prints embedded objects
PrintDrawing (Boolean)
prints draw objects
PrintDownFirst (Boolean)
if the contents of a sheet extend across several pages, they are first printed in vertically descending order, and then down the right-hand side.
PrintFormulas (Boolean)
prints the formulas instead of the calculated values
PrintZeroValues (Boolean)
prints the zero values


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools