Calc Guide

Chapter 4
Using Styles and Templates in Calc

Bringing uniformity to your spreadsheets



Copyright

This document is Copyright © 2005–2011 by its contributors as listed below. You may distribute it and/or modify it under the terms of either the GNU General Public License (http://www.gnu.org/licenses/gpl.html), version 3 or later, or the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0/), version 3.0 or later.

All trademarks within this guide belong to their legitimate owners.

Contributors

Barbara Duprey

Feedback

Please direct any comments or suggestions about this document to: documentation@libreoffice.org

Acknowledgments

This chapter is based on Chapter 4 of the OpenOffice.org 3.3 Calc Guide. The contributors to that chapter are:

Andy Brown T. J. Frazier
Peter Kupfer Nikita Telang
Jean Hollis Weber

Publication date and software version

Published 15 April 2011. Based on LibreOffice 3.3.

Note for Mac users

Some keystrokes and menu items are different on a Mac from those used in Windows and Linux. The table below gives some common substitutions for the instructions in this chapter. For a more detailed list, see the application Help.

Windows/Linux

Mac equivalent

Effect

Tools Options menu selection

LibreOffice Preferences

Access setup options

Right-click

Control+click

Open context menu

Ctrl (Control)

z (Command)

Used with other keys

F5

Shift+z+F5

Open the Navigator

F11

z+T

Open Styles & Formatting window

Contents

Copyright 2

Note for Mac users 2

What is a template? 5

What are styles? 5

Types of styles in Calc 5

Cell styles 6

Page styles 6

Accessing styles 6

Applying cell styles 7

Using the Styles and Formatting window 7

Using Fill Format mode 7

Using the Apply Style list 8

Assigning styles to shortcut keys 8

Applying page styles 8

Modifying styles 9

Style organizer 9

Cell style options 10

Numbers 10

Font 10

Font effects 10

Alignment 10

Borders 10

Background 10

Cell protection 10

Page style options 10

Page 11

Borders 12

Background 12

Header 12

Footer 12

Sheet 12

Creating new (custom) styles 12

Creating a new style using the Style dialog 12

Creating a new style from a selection 13

Creating a new style by dragging and dropping 13

Copying and moving styles 13

Deleting styles 15

Creating a spreadsheet from a template 15

Creating a template 16

Editing a template 16

Updating a spreadsheet from a changed template 17

Adding templates using the Extension Manager 18

Setting a default template 19

Setting a custom template as the default 19

Resetting the default template 19

Associating a spreadsheet with a different template 20

Organizing templates 20

Creating a template folder 20

Deleting a template folder 20

Moving a template 21

Deleting a template 21

Importing a template 21

Exporting a template 21



What is a template?

A template is a model that you use to create other documents. For example, you can create a template for invoices that has your company’s logo and address at the top of the page. New spreadsheets created from this template will all have your company’s logo and address on the first page.

Templates can contain anything that regular documents can contain, such as text, graphics, styles, and user-specific setup information such as measurement units, language, the default printer, and toolbar and menu customization.

All documents in LibreOffice are based on templates. You can create, or download and install, as many templates as you wish. If you do not specify a template when you start a new a new spreadsheet, the new spreadsheet is based on the default template for spreadsheets. If you have not specified a default template, LibreOffice uses the blank spreadsheet template that is installed with the program. See “Setting a default template” on page 19.

What are styles?

A style is a set of formats that you can apply to selected elements in a document to quickly change their appearance. When you apply a style, you apply a whole group of formats at the same time.

Many people manually format spreadsheet cells and pages without paying any attention to styles. They are used to formatting documents according to physical attributes. For example, for the contents of a cell you might specify the font family, font size, and any formatting such as bold or italic.

Styles are logical attributes. Using styles means that you stop saying “font size 14pt, Times New Roman, bold, centered”, and you start saying “Title” because you have defined the “Title” style to have those characteristics. In other words, styles means that you shift the emphasis from what the text (or page, or other element) looks like, to what the text is.

Styles help improve consistency in a document and can greatly speed up formatting. They also make major formatting changes easy. For example, you may decide to change the appearance of all subtotals in your spreadsheet to be 10 pt. Arial instead of 8 pt. Times New Roman after you have created a 15-page spreadsheet; you can change all of the subtotals in the document by simply changing the properties for the subtotal style.

Page styles assist with printing, so you don’t need to define margins, headers and footers, and other printing attributes each time you print a spreadsheet.

Types of styles in Calc

While some components of LibreOffice offer many style types, Calc offers only two:

Cell styles

Similar to paragraph styles in LibreOffice Writer, cell styles are the most basic type of style in Calc. You can apply a cell style to a cell and that cell will follow the formatting rules of the style. A range of cell styles are supplied with LibreOffice; five are shown in Figure 1.

Initially, the styles are configured so that if you change the font family of Default, then all of the other styles will change to match. We will discuss how to set this up in “Creating new (custom) styles” on page 12.

Frame9

Page styles

Page styles in Calc are applied to sheets. Although one sheet may print on several pages (pieces of paper), only one page style can be applied to a sheet. If a spreadsheet file contains more than one sheet, the different sheets can have different page styles applied to them. So, for example, a spreadsheet might contain one sheet to be printed in landscape orientation (using the Default page style) and another sheet to be printed in portrait orientation (using the Report page style).

Two page styles are supplied with Calc: Default and Report. The major difference between these two styles is that Report is portrait-oriented and Default is landscape-oriented. You can adjust many settings using page styles. You can also define as many page styles as you wish.

Because spreadsheets are primarily used onscreen and not printed, Calc does not display the page style on the screen. If you want a spreadsheet to fit on a certain page size, you have to carefully control the column width and row height, with only File Page Preview to guide you.

Despite this limitation, it’s well worth defining page styles for any spreadsheets that you are likely to print. Otherwise, if a need for printing does arise, you may lose time to trial and error.

Accessing styles

The main way to access styles is through the Styles and Formatting window (shown in Figure 2). You can open this window in several ways.

The Styles and Formatting window can be docked at the left or right of the main Calc window. To dock or undock the window, hold down the Ctrl key and double-click a gray part of the window next to the icons at the top.

The first button on the top left of the window, , is for cell styles and the second, page_styles_button, is for page styles.

Frame6

Applying cell styles

Calc provides several ways to apply cell styles:

Using the Styles and Formatting window

  1. Ensure the Styles and Formatting window is open by pressing F11 or by selecting Format Styles and Formatting. Choose the Cell Styles list by clicking the icon.

  2. Highlight the cell or group of cells to which the styles should be applied.

  3. Double-click on the cell style name.

Using Fill Format mode

This method is quite useful when you need to apply the same style to many scattered cells.

  1. Open the Styles and Formatting window and select the style you want to apply.

  2. Click the Fill Format mode icon . The mouse pointer changes to this icon.

  3. Position the moving icon on the cell to be styled and click the mouse button.

  4. To quit Fill Format mode, click the Fill Format mode icon again or close the Styles and Formatting window.

Caution

When this mode is active, a right-click anywhere in the document undoes the last Fill Format action. Be careful not to accidentally right-click and thus undo actions you want to keep.

Using the Apply Style list

You can also add an Apply Style drop-down list to the Formatting toolbar and select a style from the list to apply it to the selected cells:

  1. Click the down-arrow at the right-hand end of the Formatting toolbar (circled in Figure 3). On the drop-down menu, click Visible Buttons.

Frame8

  1. On the submenu, click Apply Style. The menus close and the Apply Style list now appears on the toolbar between the Styles and Formatting icon and the Font Name list.

Frame7

Assigning styles to shortcut keys

You can create keyboard shortcuts to apply commonly-used cell or page styles, including custom styles that you have created. See Chapter 14, Setting up and Customizing Calc, for instructions.

Applying page styles

  1. Select the sheet to be styled (click on its sheet tab at the bottom of the screen).

  2. In the Styles and Formatting window, choose the Page Styles list by clicking the page_styles_button icon. Double-click on the required page style.

To find out which page style is in use for a selected sheet, look in status bar.

Frame1

Modifying styles

To modify a style, right-click on its name in the Styles and Formatting window and choose Modify. Make the changes in the Style dialog and click OK to save the changes.

You can also modify a current cell style by selecting an already formatted cell and clicking the Update Style button on the top right hand corner of the Styles and Formatting window.

Style organizer

Right click on the name of a style in the Styles and Formatting window and click Modify to open a Style dialog similar to the one shown in Figure 6.

The Style dialog has several tabs. The Organizer tab, shown in Figure 6 for cell styles, is found in all components of LibreOffice. It provides basic information about the style. The Organizer tab for page styles is similar to the one shown for cell styles.

Frame4

Name

This is the style’s name. You cannot change the name of a built-in style, but you can change the name of a custom style.

Linked with

This option is only available for cell styles; page styles cannot be linked. If you link cell styles, then when you change the base style (for example, by changing the font from Times to Helvetica), all the linked styles will change as well. Sometimes this is exactly what you want; other times you do not want the changes to apply to all the linked styles. It pays to plan ahead.

For example, you can make a new style called red, in which the only change you want to make is for the cell text to be red. In order to make sure that the rest of the text characteristics are the same as the default style, you can link red with default. Then, any changes you make to default will be automatically applied to red.

Category

In Calc, the only option in this drop-down box is Custom styles.

Cell style options

When editing or creating cell styles, you can set several options, which are similar to those for directly formatting cells. A more detailed coverage of cell formatting is given in Chapter 2, Entering, Editing, and Formatting Data. A brief summary is provided here.

Numbers

On the Numbers tab, you can control the behavior of the data in a cell with this style. This includes specifying the type of data, the number of decimal places, and the language.

Font

Use the Font tab to choose the font for the cell’s contents.

Font effects

The Font Effects tab offers more font options including underlining, strikethrough, and color.

Alignment

Use the Alignment tab to set the horizontal and vertical alignment for the data in the cells, and rotate the text.

Borders

Use the Borders tab to set the borders for the cells, along with a shadow.

Background

Use the Background tab to choose the background color for a cell.

Cell protection

Use the Cell Protection options to protect cells against certain types of editing.

Page style options

Several of the page style options are described in more detail in Chapter 6, Printing, Exporting, and E-mailing, because manually formatting a sheet at print time (using Format Page) actually modifies the page style.

Page

Use the Page tab to edit the overall appearance of the page and its layout. The available options are shown in Figure 7.

Frame3

Paper format

Here you can set a generic paper type to be used. Letter or A4 are most common, but you can also use legal, tabloid, envelope sizes, or user-defined paper types. You can also define the orientation of the page and which print tray for the paper to come from (if your printer has more than one tray).

Margins

Here you can set the margins for the page.

Layout settings: Page layout

Here you can specify whether to apply the formatting to right (odd) pages only, left (even) pages only, or both right and left pages that use the current page style.

Mirrored formats the pages as if you want to bind the printed pages like a book.

The first page of a document is assumed to be an odd page.

Layout settings: Format

This area specifies the page numbering style for this page style.

Layout settings: Table alignment

This option specifies the alignment options for the cells on a printed page, either horizontal or vertical.

Borders

The Border and Background tabs for pages duplicate the tabs of the same name on cell styles, and are over-ridden by the cell style or manual settings. You may choose to ignore the Border and Background tabs altogether in page styles. Both tabs are illustrated with helpful diagrams.

Similar to formatting a cell style, use the Borders tab to choose whether the page should have borders, how large the borders should be, and how far the text will be from the borders.

Background

Use this tab to specify the background for this page style. You can apply either a solid color or a picture as a background.

Header

Use this tab to design and apply the header for this page style. For more detailed instructions on how to format the header, see Chapter 6, Printing, Exporting, and E-mailing.

Footer

Use this tab to design and apply the footer for this page style. For more detailed instructions on how to format the footer, see Chapter 6.

Sheet

By far the most important settings for Calc page styles are on the Sheet tab. Although the Sheet tab includes an option that sets the first page option, most of its settings involve exactly how your spreadsheet will print. See Chapter 6.

Creating new (custom) styles

You may want to add some new styles. You can do this in two ways:

Note

New styles apply only to this document; they are not saved in the template. To save new styles in a template, see “Copying and moving styles“ on page 13 and “Creating a template” on page 16.

Creating a new style using the Style dialog

To create a new style using the Style dialog, right-click in the Styles and Formatting window and choose New from the context menu.

(Cell styles only) If you want your new style to be linked with an existing style, first select that style and then right-click and choose New.

If you link styles, then when you change the base style (for example, by changing the font from Times to Helvetica), all the linked styles will change as well. Sometimes this is exactly what you want; other times you do not want the changes to apply to all the linked styles. It pays to plan ahead.

The dialogs and choices are the same for defining new styles and for modifying existing styles.

Creating a new style from a selection

You can create a new cell style by copying an existing manual format.

  1. Open the Styles and Formatting window and choose the type of style you want to create.

  2. In the document, select the formatted cell that you want to save as a style.

  3. In the Styles and Formatting window, click on the New Style from Selection icon new_styles_from_selection_button.

  4. In the Create Style dialog, type a name for the new style. The list shows the names of existing custom styles of the selected type. Click OK to save the new style.

Frame2

Creating a new style by dragging and dropping

Select a cell and drag it to the Styles and Formatting window.

Copying and moving styles

To copy a style from one spreadsheet to another, or between a spreadsheet and a template, instead of recreating it in the second spreadsheet, use the Template Management dialog.

  1. Click File Templates Organize.

  2. In the Template Management dialog (Figure 9), set the lists at the bottom to either Templates or Documents, as needed. The default is Templates on the left and Documents on the right.

Tip

To copy styles from a file that is not open, click the File button. When you return to this dialog, both lists show the selected file as well as all the currently open documents.

Frame5

  1. Open the folders and find the templates from and to which you want to copy. Double-click on the name of the template or document, and then double-click the Styles icon to show the list of individual styles (Figure 10).

Frame14

  1. To copy a style, hold down the Ctrl key and drag the name of the style from one list to the other. To move a style, drag the name of the style without holding down the Ctrl key.

  2. Repeat for each style you want to copy. If the receiving template or document has many styles, you may not see any change unless you scroll down in the list. When you are finished, click Close.

Deleting styles

You cannot remove (delete) any of Calc’s predefined styles, even if you are not using them.

You can remove any user-defined (custom) styles; but before you do, you should make sure the styles are not in use. If an unwanted style is in use, you will want to replace it with a substitute style.

Replacing styles (and then deleting the unwanted ones) can be very useful if you are dealing with a spreadsheet that has been worked on by several people.

To delete unwanted styles, right-click on them (one at a time) in the Styles and Formatting window and click Delete on the context menu. Choose Yes in the confirmation dialog.

Creating a spreadsheet from a template

To create a spreadsheet from a template:

  1. From the menu bar, choose File New Templates and Documents. The Templates and Documents dialog opens.

Frame10

  1. In the box on the left, click the Templates icon if it is not already selected. A list of template folders appears in the center box.

  2. Double-click the folder that contains the template that you want to use. A list of all the templates contained in that folder appears in the center box.

  3. Select the template that you want to use. You can preview the selected template or view the template’s properties:

  1. Click Open. The Templates and Documents dialog closes and a new document based on the selected template opens in Calc.

Creating a template

You can create a template from a document:

  1. Open a new or existing document of the type you want to make into a template (text document, spreadsheet, drawing, presentation).

  2. Add the content and styles that you want.

  3. From the menu bar, choose File Templates Save. The Templates dialog opens .

  4. In the New template field, type a name for the new template.

  5. In the Categories list, click the category to which you want to assign the template. The category you choose has no effect on the template itself; it is simply the folder in which you save the template. Choosing an appropriate folder (category) makes it easier to find the template when you want to use it. You may wish to create a folder for Calc templates.

To learn more about template folders, see “Organizing templates” on page 20.

  1. Click OK to save the new template.

Frame11

Any settings that can be added to or modified in a document can be saved in a template. For example, below are some of the settings (although not a full list) that can be included in a Calc document and then saved as a template for later use:

Templates can also contain predefined text, saving you from having to type it every time you create a new document. For example, an invoice template might contain your company’s name, address and logo.

You can also save menu and toolbar customizations in templates; see Chapter 14, Setting up and Customizing Calc, for more information.

Editing a template

You can edit a template’s styles and content, and then, if you wish, you can reapply the template’s styles to documents that were created from that template. (Note that you can only reapply styles. You cannot reapply content.)

To edit a template:

  1. From the menu bar, choose File Templates Organize. The Template Management dialog opens.

Frame12

  1. In the box on the left, double-click the folder that contains the template that you want to edit. A list of all the templates contained in that folder appears underneath the folder name.

  2. Select the template that you want to edit.

  3. Click the Commands button and choose Edit from the drop-down menu.

  4. Edit the template just as you would any other document. To save your changes, choose File Save from the menu bar.

Updating a spreadsheet from a changed template

The next time you open a spreadsheet that was created from the changed template, the following message appears.

Frame15

Click Update Styles to apply the template’s changed styles to the spreadsheet. Click Keep Old Styles if you do not want to apply the template’s changed styles to the spreadsheet (but see Caution notice below).

Caution

If you choose Keep Old Styles in the message box shown in Figure 14, that message will not appear again the next time you open the document after changing the template it is based on. You will not get another chance to update the styles from the template, although you can use the macro given in the Note below to re-enable this feature.

Note

To re-enable updating from a template:

  1. Use Tools Macros Organize Macros LibreOffice Basic. Select the document from the list, click the expansion symbol (+ or triangle), and select Standard. If Standard has an expansion symbol beside it, click that and select a module.

  2. If the Edit button is active, click it. If the Edit button is not active, click New.

  3. In the Basic window, enter the following:

Sub FixDocV3
' set UpdateFromTemplate
oDocSettings = ThisComponent.createInstance( _
"com.sun.star.document.Settings" )
oDocSettings.UpdateFromTemplate = True
End Sub 'FixDocV3

  1. Click the Run BASIC icon, then close the Basic window.

  2. Save the document.

Next time when you open this document you will have the update from template feature back.

Adding templates using the Extension Manager

The Extension Manager provides an easy way to install collections of templates, graphics, macros, or other add-ins that have been “packaged” into files with a .OXT extension. See Chapter 14, Setting Up and Customizing Calc, for more about the Extension Manager.

This Web page lists many of the available extensions: http://extensions.libreoffice.org/.

To install an extension, follow these steps:

  1. Download an extension package and save it anywhere on your computer.

  2. In LibreOffice, choose Tools Extension Manager from the menu bar. In the Extension Manager dialog, click Add.

  3. A file browser window opens. Find and select the package of templates you want to install and click Open. The package begins installing. You may be asked to accept a license agreement.

  4. When the package installation is complete, the templates are available for use through File New Templates and Documents and the extension is listed in the Extension Manager.

Frame13

Setting a default template

If you create a document by choosing File New Spreadsheet from the menu bar, LibreOffice creates the document from the Default template for spreadsheets. You can, however, set a custom template to be the default. You can reset the default later if you choose.

Setting a custom template as the default

You can set any template to be the default, as long as it is in one of the folders displayed in the Template Management dialog.

To set a custom template as the default:

  1. From the menu bar, choose File Templates Organize. The Template Management dialog opens.

  2. In the box on the left, select the folder containing the template that you want to set as the default, then select the template.

  3. Click the Commands button and choose Set As Default Template from the drop-down menu.

The next time that you create a document by choosing File New, the document will be created from this template.

Resetting the default template

To re-enable LibreOffice’s default spreadsheet template as the default:

  1. In the Template Management dialog, click any folder in the box on the left.

  2. Click the Commands button and choose Reset Default Template Spreadsheet from the drop-down menu.

The next time that you create a spreadsheet by choosing File New, it will be created from LibreOffice’s default template for spreadsheets.

Associating a spreadsheet with a different template

At times you might want to associate a spreadsheet with a different template, or perhaps you’re working with a spreadsheet that did not start from a template but you now want it associated with a template.

One of the major advantages of using templates is the ease of updating styles in more than one document, as described on page 17. If you update styles by copying them from a different template (as described on page 13), the document has no association with the template from which the styles were loaded—so you cannot use this method. What you need to do is associate the document with the different template.

For best results, the names of styles should be the same in the existing document and the new template. If they are not, you will need to use Search and Replace to replace the old styles with new ones. See Chapter 2, Entering, Editing, and Formatting Data, for more about replacing styles using Find and Replace.

  1. Use File New Templates and Documents. Choose the template you want. A new file, based on the template, opens. If the template has unwanted text or graphics in it, delete them.

  2. Open the spreadsheet you want to change. (It opens in a new window.) Press Control+A to select everything in the spreadsheet.

  3. Switch to the window containing the blank spreadsheet created in step 1, and paste the content into that spreadsheet.

  4. Save the file under a new name.

Organizing templates

LibreOffice can only use templates that are in its template folders. You can create new template folders and use them to organize your templates, and import templates into those folders. For example, you might have one template folder for report templates and another for letter templates. You can also export templates.

To begin, choose File Templates Organize from the menu bar. The Template Management dialog opens.

Note

All the actions made by the Commands button in the Template Management dialog can be made as well by right-clicking on the templates or the folders.

Creating a template folder

To create a template folder:

  1. In the Template Management dialog, click any folder.

  2. Click the Commands button and choose New from the drop-down menu. A new folder called Untitled appears.

  3. Type a name for the new folder, and then press Enter. LibreOffice saves the folder with the name that you entered.

Deleting a template folder

You cannot delete template folders supplied with LibreOffice or installed using the Extension Manager; you can only delete template folders that you have created.

To delete a template folder:

  1. In the Template Management dialog, select the folder that you want to delete.

  2. Click the Commands button and choose Delete from the drop-down menu. A message box appears and asks you to confirm the deletion. Click Yes.

Moving a template

To move a template from one template folder to another template folder:

  1. In the Template Management dialog, double-click the folder that contains the template you want to move. A list of the templates contained in that folder appears underneath the folder name.

  2. Click the template that you want to move and drag it to the desired folder. If you do not have the authority to delete templates from the source folder, this action copies the template instead of moving it.

Deleting a template

You cannot delete templates supplied with LibreOffice or installed using the Extension Manager; you can only delete templates that you have created or imported.

To delete a template:

  1. In the Template Management dialog, double-click the folder that contains the template you want to delete.

  2. Click the template that you want to delete.

  3. Click the Commands button and choose Delete from the drop-down menu. A message box appears and asks you to confirm the deletion. Click Yes.

Importing a template

If the template that you want to use is in a different location, you must import it into a LibreOffice template folder.

To import a template into a template folder:

  1. In the Template Management dialog, select the folder into which you want to import the template.

  2. Click the Commands button and choose Import Template from the drop-down menu. A standard file browser window opens.

  3. Find and select the template that you want to import and click Open. The file browser window closes and the template appears in the selected folder.

  4. If you want, type a new name for the template, and then press Enter.

Exporting a template

To export a template from a template folder to another location:

  1. In the Template Management dialog, double-click the folder that contains the template you want to export.

  2. Click the template that you want to export.

  3. Click the Commands button and choose Export Template from the drop-down menu. The Save As window opens.

  4. Find the folder into which you want to export the template and click Save.