Skip to main content

DocBuilder

Struct DocBuilder 

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

构建完整 DOCX 文档的 Fluent 构建器。

通过门面 EasyDoc::document() 方法创建。

对应 Java: com.alibaba.excel.write.ExcelBuilderImpl

§示例

EasyDoc::document("report.docx")
    .title("Report")
    .add_heading("Section 1", HeadingLevel::H1)
    .add_paragraph(Paragraph::new().add_text("Content..."))
    .add_table(Table::from_data(&rows))
    .build()?
    .save()?;

Implementations§

Source§

impl DocBuilder

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Creates a new document builder targeting the given output path.

Source

pub fn title(self, title: impl Into<String>) -> Self

Sets the document title.

Source

pub fn author(self, author: impl Into<String>) -> Self

Sets the document author.

Source

pub fn add_heading(self, text: impl Into<String>, level: HeadingLevel) -> Self

Adds a heading paragraph.

Source

pub fn add_paragraph(self, paragraph: Paragraph) -> Self

Adds a paragraph.

Source

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

Adds a table.

Source

pub fn add_image(self, image: DocImage) -> Self

Adds an image.

Source

pub fn add_page_break(self) -> Self

Adds a page break.

Source

pub fn build(self) -> Result<DocWriteExecutor>

Finalises the builder and returns a DocWriteExecutor ready to save.

§Errors

Returns an error if the document cannot be assembled.

Source

pub fn save(self) -> Result<()>

Builds and immediately saves the document to disk.

§Errors

Returns an error if the document cannot be written.

Source

pub fn save_to_writer<W: Write + Seek>(self, writer: W) -> Result<()>

Builds and writes the document to a generic writer implementing Write + Seek.

Corresponds to Hutool’s Word07Writer.flush(OutputStream) pattern. Useful for writing to memory buffers, HTTP responses, etc.

§Errors

Returns an I/O or ZIP error.

Source

pub fn save_to_bytes(self) -> Result<Vec<u8>>

Builds and returns the document as a Vec<u8>.

Useful for in-memory generation without touching the filesystem.

§Errors

Returns a ZIP error if packaging fails.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.