Skip to main content

excelize_rs/xml/
metadata.rs

1//! Metadata and rich value parts (`xl/metadata.xml`, `xl/richData/`).
2//!
3//! Ported from Go `xmlMetaData.go`.
4
5use serde::{Deserialize, Serialize};
6
7use super::common::XlsxInnerXml;
8
9/// Directly maps the metadata element. A cell in a spreadsheet application can
10/// have metadata associated with it. Metadata is just a set of additional
11/// properties about the particular cell, and this metadata is stored in the
12/// metadata xml part. There are two types of metadata: cell metadata and value
13/// metadata.
14#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename = "metadata")]
16pub struct XlsxMetadata {
17    #[serde(rename = "metadataTypes", default, skip_serializing_if = "Option::is_none")]
18    pub metadata_types: Option<XlsxInnerXml>,
19    #[serde(rename = "metadataStrings", default, skip_serializing_if = "Option::is_none")]
20    pub metadata_strings: Option<XlsxInnerXml>,
21    #[serde(rename = "mdxMetadata", default, skip_serializing_if = "Option::is_none")]
22    pub mdx_metadata: Option<XlsxInnerXml>,
23    #[serde(rename = "futureMetadata", default)]
24    pub future_metadata: Vec<XlsxFutureMetadata>,
25    #[serde(rename = "cellMetadata", default, skip_serializing_if = "Option::is_none")]
26    pub cell_metadata: Option<XlsxMetadataBlocks>,
27    #[serde(rename = "valueMetadata", default, skip_serializing_if = "Option::is_none")]
28    pub value_metadata: Option<XlsxMetadataBlocks>,
29    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
30    pub ext_lst: Option<XlsxInnerXml>,
31}
32
33/// Directly maps the futureMetadata element. This element represents future
34/// metadata information.
35#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
36pub struct XlsxFutureMetadata {
37    #[serde(rename = "bk", default)]
38    pub bk: Vec<XlsxFutureMetadataBlock>,
39    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
40    pub ext_lst: Option<XlsxInnerXml>,
41}
42
43/// Directly maps the bk element. This element represents a block of future
44/// metadata information. This is a location for storing feature extension
45/// information.
46#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub struct XlsxFutureMetadataBlock {
48    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
49    pub ext_lst: Option<XlsxInnerXml>,
50}
51
52/// Directly maps the metadata element. This element represents cell metadata
53/// information. Cell metadata is information metadata about a specific cell,
54/// and it stays tied to that cell position.
55#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct XlsxMetadataBlocks {
57    #[serde(rename = "@count", default, skip_serializing_if = "Option::is_none")]
58    pub count: Option<i64>,
59    #[serde(rename = "bk", default)]
60    pub bk: Vec<XlsxMetadataBlock>,
61}
62
63/// Directly maps the bk element. This element represents a block of metadata
64/// records.
65#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
66pub struct XlsxMetadataBlock {
67    #[serde(rename = "rc", default)]
68    pub rc: Vec<XlsxMetadataRecord>,
69}
70
71/// Directly maps the rc element. This element represents a reference to a
72/// specific metadata record.
73#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
74pub struct XlsxMetadataRecord {
75    #[serde(rename = "@t")]
76    pub t: i64,
77    #[serde(rename = "@v")]
78    pub v: i64,
79}
80
81/// Directly maps the rvData element that specifies rich value data.
82#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
83#[serde(rename = "rvData")]
84pub struct XlsxRichValueData {
85    #[serde(rename = "@count", default, skip_serializing_if = "Option::is_none")]
86    pub count: Option<i64>,
87    #[serde(rename = "rv", default)]
88    pub rv: Vec<XlsxRichValue>,
89    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
90    pub ext_lst: Option<XlsxInnerXml>,
91}
92
93/// Directly maps the rv element that specifies rich value data information for
94/// a single rich value.
95#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
96pub struct XlsxRichValue {
97    #[serde(rename = "@s")]
98    pub s: i64,
99    #[serde(rename = "v", default)]
100    pub v: Vec<String>,
101    #[serde(rename = "fb", default, skip_serializing_if = "Option::is_none")]
102    pub fb: Option<XlsxInnerXml>,
103}
104
105/// Directly maps the richValueRels element. This element specifies a list of
106/// rich value relationships.
107#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
108#[serde(rename = "richValueRels")]
109pub struct XlsxRichValueRels {
110    #[serde(rename = "rel", default)]
111    pub rels: Vec<XlsxRichValueRelRelationship>,
112    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
113    pub ext_lst: Option<XlsxInnerXml>,
114}
115
116/// Directly maps the rel element. This element specifies a relationship for a
117/// rich value property.
118#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
119pub struct XlsxRichValueRelRelationship {
120    #[serde(rename = "@r:id", default, skip_serializing_if = "String::is_empty")]
121    pub id: String,
122    /// Legacy plain `id` attribute written before 0.1.8; only used when
123    /// deserializing older files.
124    #[serde(rename = "@id", default, skip_serializing)]
125    pub legacy_id: String,
126}
127
128impl XlsxRichValueRelRelationship {
129    /// Return the relationship ID, accepting both the `r:id` form used by
130    /// Excel and the plain `id` form written by older versions of this
131    /// library.
132    pub fn rel_id(&self) -> &str {
133        if self.id.is_empty() {
134            &self.legacy_id
135        } else {
136            &self.id
137        }
138    }
139}
140
141/// Directly maps the rvStructures element. This element specifies rich value
142/// structures, which contain lists of rich value keys and the data types for
143/// the corresponding rich value data.
144#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
145#[serde(rename = "rvStructures")]
146pub struct XlsxRichValueStructures {
147    #[serde(rename = "@count", default, skip_serializing_if = "Option::is_none")]
148    pub count: Option<i64>,
149    #[serde(rename = "s", default)]
150    pub s: Vec<XlsxRichValueStructure>,
151    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
152    pub ext_lst: Option<XlsxInnerXml>,
153}
154
155/// Directly maps the s element. This element specifies the list of rich value
156/// structures.
157#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
158pub struct XlsxRichValueStructure {
159    #[serde(rename = "@t")]
160    pub t: String,
161    #[serde(rename = "k", default)]
162    pub k: Vec<XlsxRichValueKey>,
163}
164
165/// Directly maps the k element. This element specifies the rich value key.
166#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
167pub struct XlsxRichValueKey {
168    #[serde(rename = "@n")]
169    pub n: String,
170    #[serde(rename = "@t", default, skip_serializing_if = "Option::is_none")]
171    pub t: Option<String>,
172}
173
174/// Directly maps the webImagesSrd element. This element specifies a list of
175/// sets of properties associated with web image rich values.
176#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
177#[serde(rename = "webImagesSrd")]
178pub struct XlsxWebImagesSupportingRichData {
179    #[serde(rename = "webImageSrd", default)]
180    pub web_image_srd: Vec<XlsxWebImageSupportingRichData>,
181    #[serde(rename = "extLst", default, skip_serializing_if = "Option::is_none")]
182    pub ext_lst: Option<XlsxInnerXml>,
183}
184
185/// Directly maps the webImageSrd element. This element specifies a set of
186/// properties for a web image rich value.
187#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
188pub struct XlsxWebImageSupportingRichData {
189    #[serde(rename = "address", default)]
190    pub address: XlsxExternalReference,
191    #[serde(rename = "moreImagesAddress", default)]
192    pub more_images_address: XlsxExternalReference,
193    #[serde(rename = "blip", default)]
194    pub blip: XlsxExternalReference,
195}
196
197/// Directly maps the externalReference element of the external workbook
198/// references part.
199#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
200pub struct XlsxExternalReference {
201    #[serde(rename = "@r:id", default, skip_serializing_if = "Option::is_none")]
202    pub r_id: Option<String>,
203}