pub struct StructuredDocumentTag {
pub id: Option<i32>,
pub tag: Option<String>,
pub alias: Option<String>,
pub blocks: Vec<Block>,
}Expand description
A block-level structured document tag / content control (<w:sdt>, CT_SdtBlock), wrapping one
or more paragraphs/tables — one of the three alternatives EG_ContentBlockContent allows
anywhere a Block can appear (body, header/footer, table cell content, a note’s or comment’s
own content..), hence a Block variant rather than its own separate top-level list the way
Note/Comment are.
WordprocessingML defines a dozen-plus specific content-control “types” (plain text, rich text,
date picker, drop-down list, combo box, picture, citation, group, bibliography, equation,
built-in document part..) via w:sdtPr’s text/richText/date/dropDownList/. child
(CT_SdtPr’s own inner choice) — none of these are modeled here, only the type-agnostic
identifying metadata (id/tag/alias) and the content itself. SDTs remain a niche,
fast-evolving corner of the format with little real demand seen yet for anything beyond
read-only handling, so unlike every other feature in this crate there is deliberately no
creation/write API for SDTs at all. Omitting the type indicator entirely is schema-valid
regardless (CT_SdtPr’s inner choice has minOccurs="0"): Word treats a content control with
no declared type as a generic one, still fully functional.
Only the block-level form (CT_SdtBlock, wherever a Block can appear) is modeled —
WordprocessingML also defines inline-level (wrapping run content inside a paragraph), row-level
and cell-level variants (CT_SdtRun/CT_SdtRow/CT_SdtCell), none of which are supported yet.
A block-level content control can appear inside a table cell, though — since
TableCell::blocks is Vec<Block>, the same as everywhere else a Block is valid — it’s
specifically the dedicated CT_SdtCell form (matching the cell’s own boundaries rather than
wrapping arbitrary content within it) that isn’t modeled.
Fields§
§id: Option<i32>A unique identifier Word assigns the control (w:sdtPr/w:id, CT_DecimalNumber — signed
per the schema, though Word’s own generator only ever produces positive values in practice).
tag: Option<String>The programmatic tag (w:sdtPr/w:tag) — the id automation code (VBA, the OpenXML SDK..)
uses to find this control by, distinct from the human-facing alias.
alias: Option<String>The friendly/display name (w:sdtPr/w:alias) shown in Word’s UI (e.g. the control’s tab on
the Developer ribbon) — distinct from tag.
blocks: Vec<Block>The blocks that make up this control’s content, in order.
Implementations§
Source§impl StructuredDocumentTag
impl StructuredDocumentTag
Sourcepub fn new() -> StructuredDocumentTag
pub fn new() -> StructuredDocumentTag
Creates an empty structured document tag with no id/tag/alias set.
Examples found in repository?
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("docx_navigation_and_annotations.docx");
17
18 let document =
19 Document::new()
20 .with_paragraph(heading(
21 "Hyperlinks: external, and internal to a bookmark",
22 false,
23 ))
24 .with_paragraph(
25 Paragraph::new()
26 .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27 "https://www.rust-lang.org".to_string(),
28 )))
29 .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30 "https://www.rust-lang.org".to_string(),
31 )))
32 .with_run(
33 Run::new("down to the bookmark")
34 .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35 ),
36 )
37 .with_paragraph(
38 Paragraph::new()
39 .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40 .with_run(
41 Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42 ),
43 )
44 .with_paragraph(heading("Comments", true))
45 .with_paragraph(
46 Paragraph::new()
47 .with_run(Run::new("This sentence "))
48 .with_run(Run::new("needs a second look").with_comment(0))
49 .with_run(Run::new(" before it ships.")),
50 )
51 .with_comment(
52 Comment::with_text(0, "Please double-check this claim.")
53 .with_author("Reviewer")
54 .with_initials("RV"),
55 )
56 .with_paragraph(heading("Footnotes and endnotes", true))
57 .with_paragraph(
58 Paragraph::with_text("A claim that needs a footnote")
59 .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60 .with_run(Run::new(", and another that needs an endnote"))
61 .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62 )
63 .with_footnote(Note::footnote_with_text(
64 1,
65 "The footnote's own explanatory text.",
66 ))
67 .with_endnote(Note::endnote_with_text(
68 1,
69 "The endnote's own explanatory text.",
70 ))
71 .with_paragraph(heading("A structured document tag (content control)", true))
72 .with_paragraph(Paragraph::with_text("Before the content control:"))
73 .with_structured_document_tag(
74 StructuredDocumentTag::new()
75 .with_id(42)
76 .with_tag("CustomerName")
77 .with_alias("Customer name")
78 .with_paragraph(Paragraph::with_text("Acme Corp.")),
79 );
80
81 document.save_to_file(&path)?;
82 println!("Wrote {}", path.display());
83 Ok(())
84}Sourcepub fn with_id(self, id: i32) -> StructuredDocumentTag
pub fn with_id(self, id: i32) -> StructuredDocumentTag
Sets the control’s id and returns it for chaining.
Examples found in repository?
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("docx_navigation_and_annotations.docx");
17
18 let document =
19 Document::new()
20 .with_paragraph(heading(
21 "Hyperlinks: external, and internal to a bookmark",
22 false,
23 ))
24 .with_paragraph(
25 Paragraph::new()
26 .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27 "https://www.rust-lang.org".to_string(),
28 )))
29 .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30 "https://www.rust-lang.org".to_string(),
31 )))
32 .with_run(
33 Run::new("down to the bookmark")
34 .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35 ),
36 )
37 .with_paragraph(
38 Paragraph::new()
39 .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40 .with_run(
41 Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42 ),
43 )
44 .with_paragraph(heading("Comments", true))
45 .with_paragraph(
46 Paragraph::new()
47 .with_run(Run::new("This sentence "))
48 .with_run(Run::new("needs a second look").with_comment(0))
49 .with_run(Run::new(" before it ships.")),
50 )
51 .with_comment(
52 Comment::with_text(0, "Please double-check this claim.")
53 .with_author("Reviewer")
54 .with_initials("RV"),
55 )
56 .with_paragraph(heading("Footnotes and endnotes", true))
57 .with_paragraph(
58 Paragraph::with_text("A claim that needs a footnote")
59 .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60 .with_run(Run::new(", and another that needs an endnote"))
61 .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62 )
63 .with_footnote(Note::footnote_with_text(
64 1,
65 "The footnote's own explanatory text.",
66 ))
67 .with_endnote(Note::endnote_with_text(
68 1,
69 "The endnote's own explanatory text.",
70 ))
71 .with_paragraph(heading("A structured document tag (content control)", true))
72 .with_paragraph(Paragraph::with_text("Before the content control:"))
73 .with_structured_document_tag(
74 StructuredDocumentTag::new()
75 .with_id(42)
76 .with_tag("CustomerName")
77 .with_alias("Customer name")
78 .with_paragraph(Paragraph::with_text("Acme Corp.")),
79 );
80
81 document.save_to_file(&path)?;
82 println!("Wrote {}", path.display());
83 Ok(())
84}Sourcepub fn with_tag(self, tag: impl Into<String>) -> StructuredDocumentTag
pub fn with_tag(self, tag: impl Into<String>) -> StructuredDocumentTag
Sets the control’s programmatic tag and returns it for chaining.
Examples found in repository?
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("docx_navigation_and_annotations.docx");
17
18 let document =
19 Document::new()
20 .with_paragraph(heading(
21 "Hyperlinks: external, and internal to a bookmark",
22 false,
23 ))
24 .with_paragraph(
25 Paragraph::new()
26 .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27 "https://www.rust-lang.org".to_string(),
28 )))
29 .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30 "https://www.rust-lang.org".to_string(),
31 )))
32 .with_run(
33 Run::new("down to the bookmark")
34 .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35 ),
36 )
37 .with_paragraph(
38 Paragraph::new()
39 .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40 .with_run(
41 Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42 ),
43 )
44 .with_paragraph(heading("Comments", true))
45 .with_paragraph(
46 Paragraph::new()
47 .with_run(Run::new("This sentence "))
48 .with_run(Run::new("needs a second look").with_comment(0))
49 .with_run(Run::new(" before it ships.")),
50 )
51 .with_comment(
52 Comment::with_text(0, "Please double-check this claim.")
53 .with_author("Reviewer")
54 .with_initials("RV"),
55 )
56 .with_paragraph(heading("Footnotes and endnotes", true))
57 .with_paragraph(
58 Paragraph::with_text("A claim that needs a footnote")
59 .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60 .with_run(Run::new(", and another that needs an endnote"))
61 .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62 )
63 .with_footnote(Note::footnote_with_text(
64 1,
65 "The footnote's own explanatory text.",
66 ))
67 .with_endnote(Note::endnote_with_text(
68 1,
69 "The endnote's own explanatory text.",
70 ))
71 .with_paragraph(heading("A structured document tag (content control)", true))
72 .with_paragraph(Paragraph::with_text("Before the content control:"))
73 .with_structured_document_tag(
74 StructuredDocumentTag::new()
75 .with_id(42)
76 .with_tag("CustomerName")
77 .with_alias("Customer name")
78 .with_paragraph(Paragraph::with_text("Acme Corp.")),
79 );
80
81 document.save_to_file(&path)?;
82 println!("Wrote {}", path.display());
83 Ok(())
84}Sourcepub fn with_alias(self, alias: impl Into<String>) -> StructuredDocumentTag
pub fn with_alias(self, alias: impl Into<String>) -> StructuredDocumentTag
Sets the control’s friendly/display name and returns it for chaining.
Examples found in repository?
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("docx_navigation_and_annotations.docx");
17
18 let document =
19 Document::new()
20 .with_paragraph(heading(
21 "Hyperlinks: external, and internal to a bookmark",
22 false,
23 ))
24 .with_paragraph(
25 Paragraph::new()
26 .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27 "https://www.rust-lang.org".to_string(),
28 )))
29 .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30 "https://www.rust-lang.org".to_string(),
31 )))
32 .with_run(
33 Run::new("down to the bookmark")
34 .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35 ),
36 )
37 .with_paragraph(
38 Paragraph::new()
39 .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40 .with_run(
41 Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42 ),
43 )
44 .with_paragraph(heading("Comments", true))
45 .with_paragraph(
46 Paragraph::new()
47 .with_run(Run::new("This sentence "))
48 .with_run(Run::new("needs a second look").with_comment(0))
49 .with_run(Run::new(" before it ships.")),
50 )
51 .with_comment(
52 Comment::with_text(0, "Please double-check this claim.")
53 .with_author("Reviewer")
54 .with_initials("RV"),
55 )
56 .with_paragraph(heading("Footnotes and endnotes", true))
57 .with_paragraph(
58 Paragraph::with_text("A claim that needs a footnote")
59 .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60 .with_run(Run::new(", and another that needs an endnote"))
61 .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62 )
63 .with_footnote(Note::footnote_with_text(
64 1,
65 "The footnote's own explanatory text.",
66 ))
67 .with_endnote(Note::endnote_with_text(
68 1,
69 "The endnote's own explanatory text.",
70 ))
71 .with_paragraph(heading("A structured document tag (content control)", true))
72 .with_paragraph(Paragraph::with_text("Before the content control:"))
73 .with_structured_document_tag(
74 StructuredDocumentTag::new()
75 .with_id(42)
76 .with_tag("CustomerName")
77 .with_alias("Customer name")
78 .with_paragraph(Paragraph::with_text("Acme Corp.")),
79 );
80
81 document.save_to_file(&path)?;
82 println!("Wrote {}", path.display());
83 Ok(())
84}Sourcepub fn with_paragraph(self, paragraph: Paragraph) -> StructuredDocumentTag
pub fn with_paragraph(self, paragraph: Paragraph) -> StructuredDocumentTag
Appends a paragraph block and returns the control for chaining.
Examples found in repository?
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("docx_navigation_and_annotations.docx");
17
18 let document =
19 Document::new()
20 .with_paragraph(heading(
21 "Hyperlinks: external, and internal to a bookmark",
22 false,
23 ))
24 .with_paragraph(
25 Paragraph::new()
26 .with_run(Run::new("Visit the ").with_hyperlink(Hyperlink::External(
27 "https://www.rust-lang.org".to_string(),
28 )))
29 .with_run(Run::new("or jump ").with_hyperlink(Hyperlink::External(
30 "https://www.rust-lang.org".to_string(),
31 )))
32 .with_run(
33 Run::new("down to the bookmark")
34 .with_hyperlink(Hyperlink::Internal("Target".to_string())),
35 ),
36 )
37 .with_paragraph(
38 Paragraph::new()
39 .with_run(Run::new("Here is ").with_bookmark(Bookmark::new(0, "Target")))
40 .with_run(
41 Run::new("the bookmarked text.").with_bookmark(Bookmark::new(0, "Target")),
42 ),
43 )
44 .with_paragraph(heading("Comments", true))
45 .with_paragraph(
46 Paragraph::new()
47 .with_run(Run::new("This sentence "))
48 .with_run(Run::new("needs a second look").with_comment(0))
49 .with_run(Run::new(" before it ships.")),
50 )
51 .with_comment(
52 Comment::with_text(0, "Please double-check this claim.")
53 .with_author("Reviewer")
54 .with_initials("RV"),
55 )
56 .with_paragraph(heading("Footnotes and endnotes", true))
57 .with_paragraph(
58 Paragraph::with_text("A claim that needs a footnote")
59 .with_run(Run::with_note_reference(NoteReference::Footnote(1)))
60 .with_run(Run::new(", and another that needs an endnote"))
61 .with_run(Run::with_note_reference(NoteReference::Endnote(1))),
62 )
63 .with_footnote(Note::footnote_with_text(
64 1,
65 "The footnote's own explanatory text.",
66 ))
67 .with_endnote(Note::endnote_with_text(
68 1,
69 "The endnote's own explanatory text.",
70 ))
71 .with_paragraph(heading("A structured document tag (content control)", true))
72 .with_paragraph(Paragraph::with_text("Before the content control:"))
73 .with_structured_document_tag(
74 StructuredDocumentTag::new()
75 .with_id(42)
76 .with_tag("CustomerName")
77 .with_alias("Customer name")
78 .with_paragraph(Paragraph::with_text("Acme Corp.")),
79 );
80
81 document.save_to_file(&path)?;
82 println!("Wrote {}", path.display());
83 Ok(())
84}Sourcepub fn with_table(self, table: Table) -> StructuredDocumentTag
pub fn with_table(self, table: Table) -> StructuredDocumentTag
Appends a table block and returns the control for chaining.
Sourcepub fn paragraphs(&self) -> impl Iterator<Item = &Paragraph>
pub fn paragraphs(&self) -> impl Iterator<Item = &Paragraph>
Iterates over this control’s paragraphs only, skipping tables and nested structured document tags.
Trait Implementations§
Source§impl Clone for StructuredDocumentTag
impl Clone for StructuredDocumentTag
Source§fn clone(&self) -> StructuredDocumentTag
fn clone(&self) -> StructuredDocumentTag
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more