Styles and Templates

From Wiki
Revision as of 16:14, 2 September 2011 by Sancho (talk | contribs) (Основной текст)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search





Styles

Styles are named lists containing formatting attributes. They work in all applications of OpenOffice.org and help to significantly simplify formatting. If the user changes one of the attributes of a style, then OpenOffice.org automatically adjusts all document sections depending on the attribute. The user can therefore, for example, change the font type of all level one headers by means of a central modification in the document.

Style Types

Depending on the relevant document types, OpenOffice.org recognizes a whole range of different types of styles.

OpenOffice.org Writer supports the following types of styles:

  • Character styles
  • Paragraph styles
  • Frame styles
  • Page styles
  • Numbering styles

OpenOffice.org Calc supports the following types of styles:

  • Cell styles
  • Page styles

OpenOffice.org Impress supports the following types of styles:

  • Character element styles
  • Presentation styles

In OpenOffice.org terminology, the different types of styles are called StyleFamilies in accordance with the com.sun.star.style.StyleFamily service on which they are based. The StyleFamilies are accessed by means of the document object:

Dim Doc As Object
Dim Sheet As Object 
Dim StyleFamilies As Object 
Dim CellStyles As Object

Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
CellStyles = StyleFamilies.getByName("CellStyles")

The example uses the StyleFamilies property of a spreadsheet document to establish a list containing all available cell styles.

The individual styles can be accessed directly by means of an index:

Dim Doc As Object
Dim Sheet As Object
Dim StyleFamilies As Object 
Dim CellStyles As Object
Dim CellStyle As Object
Dim I As Integer

Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
CellStyles = StyleFamilies.getByName("CellStyles")

For I = 0 To CellStyles.Count - 1
  CellStyle = CellStyles(I)
  MsgBox CellStyle.Name
Next I

The loop added since the previous example displays the names of all cell styles one after another in a message box.

Documentation note.png The reference CellStyles(I) corresponds to the method getByIndex(), which is optional for these style container objects. It may not be available in all types of documents.

The method getByName() is mandatory, and should always be available.


Details about various formatting options

Each type of style provides a whole range of individual formatting properties. Here is an overview of the most important formatting properties and the points at which they are explained:

The format properties are by no means restricted to the applications in which these are explained, but instead can be used universally. For example, most of the page properties described in Spreadsheets can therefore be used not only in OpenOffice.org Calc, but also in OpenOffice.org Writer.

More information about working with styles can be found in the Default values for character and paragraph properties section in Text Documents.


Templates

Templates are auxiliary documents. They provide a very convenient way to store, maintain, and distribute styles, macros, boiler-plate text, and other useful things.


Document and Template Types

Each major type of OpenOffice.org document has its own associated template type. In general, and for styles in particular, you can access information within a template in the same way you would access the same information in the associated document type. In other words, code (like the above examples) that works in a particular document type should also work for the associated template type.


Automatic Update

Most template types – Draw templates are the exception – have an automatic-update feature. If a style in the template has been changed, and you open a document created with that template, you will see a message asking whether to update the styles in the document. If you click on Yes, the new or changed styles will be copied into the document. Styles deleted from the template are not removed from documents.

A problem may arise if you click on No: the styles will not be updated, and the automatic-update feature will be turned off. As of OpenOffice.org Version 3.1, this status does not show in the GUI, nor is there any GUI way to re-enable the feature. (For Writer documents only, you can use the Template Changer extension to set this feature again.)

The following subroutine, adapted from the Template Changer extension, will re-enable the update feature for all document types.

Sub FixUpdate
  Dim oDocSettings as Object
  oDocSettings = ThisComponent.createInstance( "com.sun.star.document.Settings" )
  oDocSettings.UpdateFromTemplate = True
End Sub 'FixUpdate
Content on this page is licensed under the Public Documentation License (PDL).