Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

A DOCX document

Implementations§

Source§

impl Document

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a document from a file path

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Open a document from bytes

Source

pub fn new() -> Self

Create a new empty document

Source

pub fn save<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Save the document to a file

Source

pub fn to_bytes(&mut self) -> Result<Vec<u8>>

Save the document to bytes

Source

pub fn paragraphs(&self) -> impl Iterator<Item = &Paragraph>

Get all paragraphs

Source

pub fn paragraph_count(&self) -> usize

Get paragraph count

Source

pub fn paragraph(&self, index: usize) -> Option<&Paragraph>

Get paragraph by index

Source

pub fn tables(&self) -> impl Iterator<Item = &Table>

Get all tables

Source

pub fn table_count(&self) -> usize

Get table count

Source

pub fn table(&self, index: usize) -> Option<&Table>

Get table by index

Source

pub fn text(&self) -> String

Get all text in the document

Source

pub fn package(&self) -> &Package

Get the underlying package

Source

pub fn body_mut(&mut self) -> &mut Body

Get mutable body

Source

pub fn add_paragraph(&mut self, text: impl Into<String>) -> &mut Paragraph

Add a paragraph with text

Source

pub fn add_empty_paragraph(&mut self) -> &mut Paragraph

Add an empty paragraph

Source

pub fn numbering(&self) -> Option<&Numbering>

Get numbering definitions

Source

pub fn numbering_mut(&mut self) -> Option<&mut Numbering>

Get mutable numbering definitions

Source

pub fn is_list_item(&self, para: &Paragraph) -> bool

Check if a paragraph is a list item

Source

pub fn is_bullet_list_item(&self, para: &Paragraph) -> bool

Check if a paragraph is a bullet list item

Source

pub fn list_level(&self, para: &Paragraph) -> Option<u32>

Get the list level of a paragraph (0-8), or None if not a list item

Source

pub fn list_format(&self, para: &Paragraph) -> Option<&NumberFormat>

Get the number format for a list item

Source

pub fn add_table(&mut self, table: Table) -> &mut Table

Add a table to the document

Source

pub fn add_table_with_size(&mut self, rows: usize, cols: usize) -> &mut Table

Create and add a table with specified rows and columns

Source

pub fn table_mut(&mut self, index: usize) -> Option<&mut Table>

Get mutable table by index

Trait Implementations§

Source§

impl Debug for Document

Source§

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

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

impl Default for Document

Source§

fn default() -> Self

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

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> 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, 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.