Overall Document Features
Styles
A style contains all formatting properties for a specific object. All styles of the same type are contained in a collection named a style family. Each style family has a specific name to identify it in the collection. In OpenOffice.org API Calc, there are two style families named CellStyles and PageStyles. A cell style can be applied to a cell, a cell range, or all cells of the spreadsheet. A page style can be applied to a spreadsheet itself.
The collection of style families is available from the spreadsheet document with the com.sun.star.style.XStyleFamiliesSupplier's method getStyleFamilies()
. The general handling of styles is described in this section, therefore this chapter focuses on the spreadsheet specific style properties.
Cell Styles
Cell styles are predefined packages of format settings that are applied in a single step.
A cell style is represented by the service com.sun.star.sheet.TableCellStyle. If a formatting property is applied directly to a cell, it covers the property of the applied cell style. This service does not support the property CellStyle
. The name of the style is set with the interface com.sun.star.container.XNamed.
The following example creates a new cell style with gray background. The xDocument
is the com.sun.star.sheet.XSpreadsheetDocument interface of a spreadsheet document.
// get the cell style container com.sun.star.style.XStyleFamiliesSupplier xFamiliesSupplier = (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface( com.sun.star.style.XStyleFamiliesSupplier.class, xDocument); com.sun.star.container.XNameAccess xFamiliesNA = xFamiliesSupplier.getStyleFamilies(); Object aCellStylesObj = xFamiliesNA.getByName("CellStyles"); com.sun.star.container.XNameContainer xCellStylesNA = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, aCellStylesObj); // create a new cell style com.sun.star.lang.XMultiServiceFactory xServiceManager = (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, xDocument); Object aCellStyle = xServiceManager.createInstance("com.sun.star.style.CellStyle"); xCellStylesNA.insertByName("MyNewCellStyle", aCellStyle); // modify properties of the new style com.sun.star.beans.XPropertySet xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, aCellStyle); xPropSet.setPropertyValue("CellBackColor", new Integer(0x888888)); xPropSet.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false));
Page Styles
A page style is represented by the service com.sun.star.sheet.TablePageStyle. It contains the service com.sun.star.style.PageStyle and additional spreadsheet specific page properties.
The properties LeftPageFooterContent
, LeftPageHeaderContent
, RightPageFooterContent
and RightPageHeaderContent
return the interface com.sun.star.sheet.XHeaderFooterContent for the headers and footers for the left and right pages. Headers and footers are represented by the service com.sun.star.sheet.HeaderFooterContent. Each header or footer object contains three text objects for the left, middle and right portion of a header or footer. The methods getLeftText()
, getCenterText()
and getRightText()
return the interface com.sun.star.text.XText of these text portions.
Content on this page is licensed under the Public Documentation License (PDL). |