pub struct Document<R> { /* private fields */ }Expand description
A Word document (.docx file).
This is the main entry point for reading Word documents. The document stores
parsed generated types (types::Document, types::Styles) that can be
queried using the extension traits in ext.
For writing documents, use DocumentBuilder.
Implementations§
Source§impl<R: Read + Seek> Document<R>
impl<R: Read + Seek> Document<R>
Sourcepub fn from_reader(reader: R) -> Result<Self>
pub fn from_reader(reader: R) -> Result<Self>
Open a Word document from a reader.
Sourcepub fn body(&self) -> &Body
pub fn body(&self) -> &Body
Get the document body.
Returns the generated Body type. Use extension traits from ext to
access paragraphs, runs, and text content.
Sourcepub fn package_mut(&mut self) -> &mut Package<R>
pub fn package_mut(&mut self) -> &mut Package<R>
Get a mutable reference to the underlying package.
Sourcepub fn core_properties(&self) -> Option<&CoreProperties>
pub fn core_properties(&self) -> Option<&CoreProperties>
Get the core document properties (title, author, etc.).
Returns None if the document doesn’t have a core properties part.
Sourcepub fn app_properties(&self) -> Option<&AppProperties>
pub fn app_properties(&self) -> Option<&AppProperties>
Get the extended application properties (word count, page count, etc.).
Returns None if the document doesn’t have an app properties part.
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Extract all text from the document.
Paragraphs are separated by newlines.
Sourcepub fn get_image_data(&mut self, rel_id: &str) -> Result<ImageData>
pub fn get_image_data(&mut self, rel_id: &str) -> Result<ImageData>
Get image data by relationship ID.
Looks up the relationship, reads the image file from the package, and returns the image data with its content type.
Sourcepub fn get_hyperlink_url(&self, rel_id: &str) -> Option<&str>
pub fn get_hyperlink_url(&self, rel_id: &str) -> Option<&str>
Get the URL for a hyperlink by its relationship ID.
Returns None if the relationship doesn’t exist.
Sourcepub fn doc_relationships(&self) -> &Relationships
pub fn doc_relationships(&self) -> &Relationships
Get document relationships (for advanced use).
Sourcepub fn get_header(&mut self, rel_id: &str) -> Result<HeaderFooter>
pub fn get_header(&mut self, rel_id: &str) -> Result<HeaderFooter>
Load a header part by its relationship ID.
Returns the parsed header as a generated HeaderFooter type.
Load a footer part by its relationship ID.
Returns the parsed footer as a generated HeaderFooter type.
Sourcepub fn get_footnotes(&mut self) -> Result<Footnotes>
pub fn get_footnotes(&mut self) -> Result<Footnotes>
Load the footnotes part.
Returns the parsed footnotes as a generated Footnotes type.
Returns Error::MissingPart if the document has no footnotes.xml.
Sourcepub fn get_endnotes(&mut self) -> Result<Endnotes>
pub fn get_endnotes(&mut self) -> Result<Endnotes>
Load the endnotes part.
Returns the parsed endnotes as a generated Endnotes type.
Returns Error::MissingPart if the document has no endnotes.xml.
Sourcepub fn get_comments(&mut self) -> Result<Comments>
pub fn get_comments(&mut self) -> Result<Comments>
Load the comments part.
Returns the parsed comments as a generated Comments type.
Returns Error::MissingPart if the document has no comments.xml.
Sourcepub fn get_settings(&mut self) -> Result<DocumentSettings>
pub fn get_settings(&mut self) -> Result<DocumentSettings>
Load the document settings.
Returns the parsed settings from word/settings.xml.
Returns Error::MissingPart if the document has no settings.xml.
Sourcepub fn get_chart(&mut self, rel_id: &str) -> Result<ChartSpace>
pub fn get_chart(&mut self, rel_id: &str) -> Result<ChartSpace>
Load a chart part by its relationship ID.
Looks up the chart relationship in the document’s .rels file, reads the
chart XML part (e.g. word/charts/chart1.xml), and parses it as a
ChartSpace using the ooxml-dml generated parser.
Chart relationship IDs can be found by walking drawing elements with
DrawingChartExt::all_chart_rel_ids().
Requires the wml-charts feature.
ECMA-376 Part 1, §21.2.2.27 (chartSpace).