Skip to main content

DocumentProperties

Struct DocumentProperties 

Source
pub struct DocumentProperties {
    pub title: Option<String>,
    pub author: Option<String>,
    pub subject: Option<String>,
    pub keywords: Option<String>,
    pub company: Option<String>,
    pub manager: Option<String>,
    pub hyperlink_base: Option<String>,
    pub custom_properties: Vec<(String, CustomPropertyValue)>,
}
Expand description

Document metadata (docProps/core.xml’s Dublin Core fields plus docProps/app.xml’s Company/Manager/HyperlinkBase, and docProps/custom.xml’s user-defined properties) — extended by. Before both core.xml/app.xml were always written but always empty/boilerplate (see writer.rs’s to_core_properties_xml/ to_app_properties_xml). Only the handful of fields a real document typically carries are modeled — docProps/core.xml’s lastModifiedBy/revision/created/modified/category/contentStatus are still not.

Fields§

§title: Option<String>

docProps/core.xml’s <dc:title>.

§author: Option<String>

docProps/core.xml’s <dc:creator>.

§subject: Option<String>

docProps/core.xml’s <dc:subject>.

§keywords: Option<String>

docProps/core.xml’s <cp:keywords>.

§company: Option<String>

docProps/app.xml’s <Company>.

§manager: Option<String>

docProps/app.xml’s <Manager>.

§hyperlink_base: Option<String>

docProps/app.xml’s <HyperlinkBase> (the base URL relative hyperlinks in this workbook resolve against) — point 57.

§custom_properties: Vec<(String, CustomPropertyValue)>

User-defined custom document properties (docProps/custom.xml, CT_Properties/CT_Property) — point 56, visible in Excel’s File > Info > Properties > Advanced Properties > Custom tab. A Vec of (name, value) pairs, not a map: insertion order is preserved and determines the sequential pid each entry gets when written (2, 3, 4. — 0/1 are reserved by the format and never assigned), matching word-ooxml’s own Document.custom_properties convention exactly (including which 4 CustomPropertyValue variants are modeled, for consistency across this workspace’s crates). Only written if non-empty, same “optional part” posture as table_styles/external_links elsewhere in this crate.

Implementations§

Source§

impl DocumentProperties

Source

pub fn new() -> DocumentProperties

Creates document properties with every field unset (equivalent to DocumentProperties::default(), only useful as a starting point for the with_* builders).

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 68)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_title(self, title: impl Into<String>) -> DocumentProperties

Sets the title and returns the properties for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 69)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_author(self, author: impl Into<String>) -> DocumentProperties

Sets the author and returns the properties for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 70)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_subject(self, subject: impl Into<String>) -> DocumentProperties

Sets the subject and returns the properties for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 71)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_keywords(self, keywords: impl Into<String>) -> DocumentProperties

Sets the keywords and returns the properties for chaining.

Source

pub fn with_company(self, company: impl Into<String>) -> DocumentProperties

Sets the company and returns the properties for chaining.

Source

pub fn with_manager(self, manager: impl Into<String>) -> DocumentProperties

Sets the manager and returns the properties for chaining.

Sets the hyperlink base and returns the properties for chaining — point 57.

Source

pub fn with_custom_property( self, name: impl Into<String>, value: CustomPropertyValue, ) -> DocumentProperties

Appends a custom document property and returns the properties for chaining. See custom_properties’s doc comment for why order matters (it determines each entry’s pid).

Examples found in repository?
examples/xlsx_workbook_metadata.rs (lines 72-75)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}

Trait Implementations§

Source§

impl Clone for DocumentProperties

Source§

fn clone(&self) -> DocumentProperties

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DocumentProperties

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for DocumentProperties

Source§

fn default() -> DocumentProperties

Returns the “default value” for a type. Read more
Source§

impl PartialEq for DocumentProperties

Source§

fn eq(&self, other: &DocumentProperties) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DocumentProperties

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.