Module spreadsheet_ods::style

source ·
Expand description

Styles define a large number of attributes.

They are split along style:family into separate structs like CellStyle, ParagraphStyle etc. These are the main building blocks that will be used to set the properties of each style.

Such a style has to be added to the workbook, which returns a reference to the added style (CellStyle -> CellStyleRef). These provide only a loose coupling to the style itself, but allow a better differentiation of the different style-families. Wherever a style can be used a reference of the correct type is expected.

use spreadsheet_ods::{CellRef, Sheet, WorkBook};
use spreadsheet_ods::style::{StyleOrigin, StyleUse, CellStyle};
use spreadsheet_ods::color::Rgb;
use icu_locid::locale;
use spreadsheet_ods::style::stylemap::StyleMap;
use spreadsheet_ods::condition::{Condition};

let mut wb = WorkBook::new(locale!("en_US"));

let mut cs1 = CellStyle::new("ce12", &"num2".into());
cs1.set_color(Rgb::new(192, 128, 0));
cs1.set_font_bold();
let cs1 = wb.add_cellstyle(cs1);

let mut cs2 = CellStyle::new("ce11", &"num2".into());
cs2.set_color(Rgb::new(0, 192, 128));
cs2.set_font_bold();
let cs2 = wb.add_cellstyle(cs2);

let mut cs3 = CellStyle::new("ce13", &"num4".into());
cs3.push_stylemap(StyleMap::new(Condition::content_eq("BB"), "ce12".into(), Some(CellRef::remote("sheet0", 4, 3))));
cs3.push_stylemap(StyleMap::new(Condition::content_eq("CC"), "ce11".into(), Some(CellRef::remote("sheet0", 4, 3))));
let cs3 = wb.add_cellstyle(cs3);



let mut sheet = Sheet::new("sample");
sheet.set_styled_value(0, 0, 1234, &cs1);
sheet.set_styled_value(0, 1, 5678, &cs2);

From the specification:

The style:style element represents styles.

Styles defined by the style:style element use a hierarchical style model. The style:style element supports inheritance of formatting properties by a style from its parent style. A parent style is specified by the style:parent-style-name attribute on a style:style element.

The determination of the value of a formatting property begins with any style that is specified by an element. If the formatting property is present in that style, its value is used. If that style does not specify a value for that formatting property and it has a parent style, the value of the formatting element is taken from the parent style, if present. If the parent style does not have a value for the formatting property, the search for the formatting property value continues up parent styles until either the formatting property has been found or a style is found with no parent style. If a search of the parent styles of a style does not result in a value for a formatting property, the determination of its value depends on the style family and the element to which a style is applied. For styles with family text which are applied to elements which are contained in another element that specifies a style with family text, the search continues within the text style that is applied to the nearest ancestor element that specifies a style with family text, and continues in its parent styles.

For styles with family text which are applied to elements which are contained in a paragraph element 6.1.1, the search continues within the paragraph style that is applied to the paragraph element, and continues in its parent styles. For styles with family paragraph which are applied to paragraph elements which are contained in a drawing shape or a chart element, the search continues within the graphic, presentation or chart style that is applied to the drawing object or chart element, and continues in its parent styles. For styles with family paragraph which are applied to paragraph elements which are contained in a table cell, the search continues within the table-cell style that is applied to the table-cell, and continues in its parent styles. If a value for the formatting property has not been found, the search continues as defined for styles with family table-cell.

For styles with family table-cell which are applied to a table cell, the search continues with the style specified by the table:default-cell-style-name attribute 19.619 of the table cell’s table:table-row parent element, if present, and then with the style specified by the table:default-cell-style-name attribute of the table:table-column element associated with the table cell.

In all other cases, or if a value for the formatting property has not been found by any of the family specific rules, a default style 16.4 that has the same family as the style initially declared sets the value. If a value has not been found by these steps, but this specification defines a default value, then this default value is used. In all remaining cases an implementation-dependent value is used.

Modules§

  • Conditional styles.
  • Defines tabstops for paragraph styles.
  • All kinds of units for use in style attributes.

Structs§

  • Reference
  • Describes the style information for a cell.
  • Reference
  • Describes the style information for a table column. Hardly ever used. It’s easier to set the col_width via Sheet::set_col_width
  • Reference
  • The style:font-face element represents a font face declaration which documents the properties of a font used in a document.
  • Styles of this type can occur in an odt file. This is only used as a place to put this stuff when reading the ods.
  • Reference
  • Header/Footer data. Can be seen as three regions left/center/right or as one region. In the first case region* contains the data, in the second it’s content. Each is a TextTag of parsed XML-tags.
  • Style attributes for header/footer.
  • Defines the structure and content for a page. Refers to a PageStyle for layout information. It must be attached to a Sheet to be used.
  • Reference
  • The style:page-layout element represents the styles that specify the formatting properties of a page.
  • Reference
  • Paragraph style.
  • Reference
  • Describes the style information for a table row. Hardly ever used. It’s easier to set the row_height via Sheet::set_row_height.
  • Reference
  • Text style. This is not used for cell-formatting. Use CellStyle instead.
  • Reference
  • Describes the style information for a table.
  • Reference
  • Text style. This is not used for cell-formatting. Use CellStyle instead.
  • Reference

Enums§

  • Origin of a style. Content.xml or Styles.xml.
  • Placement of a style. office:styles or office:automatic-styles Defines the usage pattern for the style.