[][src]Crate spreadsheet_ods

Implements reading and writing of ODS Files.

use spreadsheet_ods::{WorkBook, Sheet, Value};
use chrono::NaiveDate;
use spreadsheet_ods::format;
use spreadsheet_ods::formula;
use spreadsheet_ods::{Length, cm, mm};
use spreadsheet_ods::style::{Style, AttrText, TextRelief, AttrFoBorder, Border};
use color::Rgb;

let mut wb = spreadsheet_ods::read_ods("tests/example.ods").unwrap();

let sheet = wb.sheet(0);
let n = sheet.value(0,0).as_f64_or(0f64);
if let Value::Boolean(v) = sheet.value(1,1) {
    if *v {
        println!("was true");
    }
}

let mut sheet = wb.sheet_mut(1);
sheet.set_value(0, 0, 21.4f32);
sheet.set_value(0, 1, "foo");
sheet.set_styled_value(0, 2, NaiveDate::from_ymd(2020, 03, 01), "nice_date_style");
sheet.set_formula(0, 3, format!("of:={}+1", formula::fcellref(0,0)));

let mut sheet = Sheet::new_with_name("sample");
sheet.set_value(5,5, "sample");
wb.push_sheet(sheet);

let nice_date_format = format::create_date_dmy_format("nice_date_format");
wb.add_format(nice_date_format);

let mut nice_date_style = Style::new_cell_style("nice_date_style", "nice_date_format");
nice_date_style.text_mut().set_font_bold();
nice_date_style.text_mut().set_font_relief(TextRelief::Engraved);
nice_date_style.cell_mut().set_border(mm!(0.2), Border::Dashed, Rgb::new(192, 72, 72));
wb.add_style(nice_date_style);

spreadsheet_ods::write_ods(&wb, "test_out/tryout.ods");

This does not cover the entire ODS spec.

What is supported:

  • Spread-sheets

    • Handles all datatypes
      • Uses time::Duration
      • Uses chrono::NaiveDate and NaiveDateTime
      • Supports rust_decimal::Decimal
    • Column/Row/Cell styles
    • Formulas
      • Only as strings, but support functions for cell/range references.
    • Row/Column spans
    • Header rows/columns, print ranges
    • Formatted text as xml text.
  • Formulas

    • Only as strings.
    • Utilities for cell/range references.
  • Styles

    • Default styles per data type.
    • Preserves all style attributes.
    • Table, row, column, cell, paragraph and text styles.
    • Stylemaps (basic support)
    • Support for setting most style attributes.
  • Value formatting

    • The whole set is available.
    • Utility functions for common formats.
  • Fonts

    • Preserves all font attributes.
    • Basic support for setting this stuff.
  • Page layouts

    • Style attributes
    • Header/footer content as XML text.
  • Cell/range references

    • Parsing and formatting

What is not supported:

  • Spreadsheets
    • Row and column grouping
  • ...

There are a number of features that are not parsed completely, but which are stored as a XML structure. This might work as long as these features don't refer to data that is no longer valid after some modification. But they are written back to the ods.

Anyway those are:

  • tracked-changes
  • variable-decls
  • sequence-decls
  • user-field-decls
  • dde-connection-decls
  • calculation-settings
  • content-validations
  • label-ranges
  • named-expressions
  • database-ranges
  • data-pilot-tables
  • consolidation
  • dde-links
  • table:desc
  • table-source
  • dde-source
  • scenario
  • forms
  • shapes
  • calcext:conditional-formats

When storing a previously read ODS file, all the contained files are copied to the new file, except styles.xml and content.xml. For a new ODS file mimetype, manifest, manifest.rdf, meta.xml are filled with minimal defaults. There is no way to set these for now.

Re-exports

pub use error::OdsError;
pub use format::ValueFormat;
pub use refs::CellRange;
pub use refs::CellRef;
pub use refs::ColRange;
pub use refs::RowRange;
pub use style::Style;

Modules

defaultstyles
error
format

Defines ValueFormat for formatting related issues

formula

For now defines functions to create cell references for formulas.

refs

Defines types for cell references.

style

Defines the basic structures for table styling, PageLayout and Style

text

Text is stored as a simple String whenever possible. When there is a more complex structure, a TextTag is constructed which mirrors the Xml tree structure.

xmltree

Defines an XML-Tree. This is used for parts of the spreadsheet that are not destructured in detail, but simply passed through. With a little bit of luck there is still some meaning left after modifying the rest.

Macros

cm

Centimeters.

currency

currency value

deg

deg angles. 360°

em

Length depending on font size.

grad

grad angles. 400°

inch

Inches.

mm

Millimeters.

pc

Pica. 12/72"

percent

currency value

pt

Point. 1/72"

rad

radians angle.

Structs

SCell

One Cell of the spreadsheet.

Sheet

One sheet of the spreadsheet.

WorkBook

Book is the main structure for the Spreadsheet.

Enums

Angle

Value type for angles.

Length

Value type for lengths.

Value

Content-Values

ValueType

Datatypes

Visibility

Visibility of a column or row.

Functions

read_ods

Reads an ODS-file.

write_ods

Writes the ODS file.

Type Definitions

ucell

Cell index type for row/column indexes.