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
impl DocBuilder
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Creates a new document builder targeting the given output path.
Sets the document author.
Sourcepub fn add_heading(self, text: impl Into<String>, level: HeadingLevel) -> Self
pub fn add_heading(self, text: impl Into<String>, level: HeadingLevel) -> Self
Adds a heading paragraph.
Sourcepub fn add_paragraph(self, paragraph: Paragraph) -> Self
pub fn add_paragraph(self, paragraph: Paragraph) -> Self
Adds a paragraph.
Sourcepub fn add_page_break(self) -> Self
pub fn add_page_break(self) -> Self
Adds a page break.
Sourcepub fn build(self) -> Result<DocWriteExecutor>
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.
Sourcepub fn save(self) -> Result<()>
pub fn save(self) -> Result<()>
Builds and immediately saves the document to disk.
§Errors
Returns an error if the document cannot be written.
Sourcepub fn save_to_writer<W: Write + Seek>(self, writer: W) -> Result<()>
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.
Auto Trait Implementations§
impl Freeze for DocBuilder
impl RefUnwindSafe for DocBuilder
impl Send for DocBuilder
impl Sync for DocBuilder
impl Unpin for DocBuilder
impl UnsafeUnpin for DocBuilder
impl UnwindSafe for DocBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more