Skip to main content

excelize_rs/xml/
comments.rs

1//! Comments part (`xl/commentsN.xml`).
2//!
3//! Ported from Go `xmlComments.go`.
4
5use serde::{Deserialize, Serialize};
6
7use super::common::{RichTextRun, XlsxPhoneticPr, XlsxPhoneticRun, XlsxR};
8
9/// Directly maps the comments element.
10#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(rename = "comments", rename_all = "PascalCase")]
12pub struct XlsxComments {
13    #[serde(rename = "authors", default)]
14    pub authors: XlsxAuthor,
15    #[serde(rename = "commentList", default)]
16    pub comment_list: XlsxCommentList,
17    #[serde(skip)]
18    pub cells: Vec<String>,
19}
20
21/// Holds the list of authors.
22#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct XlsxAuthor {
24    #[serde(rename = "author", default)]
25    pub author: Vec<String>,
26}
27
28/// Container for the list of comments.
29#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
30pub struct XlsxCommentList {
31    #[serde(rename = "comment", default)]
32    pub comment: Vec<XlsxComment>,
33}
34
35/// A single comment.
36#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
37pub struct XlsxComment {
38    #[serde(rename = "@ref", default)]
39    pub r#ref: String,
40    #[serde(rename = "@authorId", default)]
41    pub author_id: i32,
42    #[serde(rename = "text", default)]
43    pub text: XlsxText,
44}
45
46/// Rich text content of a comment.
47#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
48pub struct XlsxText {
49    #[serde(rename = "t", default)]
50    pub t: Option<String>,
51    #[serde(rename = "r", default)]
52    pub r: Vec<XlsxR>,
53    #[serde(rename = "rPh", default)]
54    pub r_ph: Option<XlsxPhoneticRun>,
55    #[serde(rename = "phoneticPr", default)]
56    pub phonetic_pr: Option<XlsxPhoneticPr>,
57}
58
59/// Comment information used in the public API.
60#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
61pub struct Comment {
62    #[serde(default)]
63    pub author: String,
64    #[serde(rename = "AuthorID", default)]
65    pub author_id: i32,
66    #[serde(default)]
67    pub cell: String,
68    #[serde(default)]
69    pub text: String,
70    #[serde(default)]
71    pub width: u32,
72    #[serde(default)]
73    pub height: u32,
74    #[serde(default)]
75    pub paragraph: Vec<RichTextRun>,
76}