Skip to main content

DocEditor

Struct DocEditor 

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

已打开的 DOCX 文件,准备进行修改。

通过门面 EasyDoc::edit() 方法创建。包装 office_oxideEditableDocument 以支持文本替换和保存。

§示例

EasyDoc::edit("existing.docx")?
    .replace_text("{name}", "Alice")
    .replace_text("{date}", "2026-07-21")
    .save()?;

Implementations§

Source§

impl DocEditor

Source

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

Opens an existing DOCX file for editing.

§Errors

Returns I/O or format errors.

Source

pub fn replace_text(self, find: &str, replace: &str) -> Self

Replaces all occurrences of find with replace in the document text.

Corresponds to Hutool’s placeholder replacement pattern (which Hutool itself does not provide — users must use raw POI).

Returns the number of replacements made.

Source

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

Saves the modified document, overwriting the original file.

§Errors

Returns I/O errors.

Source

pub fn save_as(self, path: impl AsRef<Path>) -> Result<()>

Saves the modified document to a new path.

§Errors

Returns I/O errors.

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.