Skip to main content

TextBody

Struct TextBody 

Source
pub struct TextBody {
    pub body_properties: Option<BodyProperties>,
    pub paragraphs: Vec<Paragraph>,
}
Expand description

文本体 <p:txBody>

对应 python-pptx 的 TextFrame 类:提供段落列表 + 自动调整 / 边距 / 垂直对齐 / 换行等“文本框级“属性。

Fields§

§body_properties: Option<BodyProperties>§paragraphs: Vec<Paragraph>

Implementations§

Source§

impl TextBody

Source

pub fn new() -> TextBody

Source

pub fn write_xml(&self, w: &mut XmlWriter, tag: &str)

写 XML。

tag 参数指定外层元素标签名(如 "p:txBody" 用于 PPTX, "c:txBody" 用于 chart 标题等)。这样本类型可在不同格式间复用。

Source

pub fn text(&self) -> String

取所有文本(段间 \n)。

Source

pub fn first_paragraph(&self) -> Option<&Paragraph>

取首个段落(TextFrame.paragraphs[0] 的等价物)。

Source

pub fn first_paragraph_mut(&mut self) -> Option<&mut Paragraph>

取首个段落的可变引用。

Source

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

取第 idx 个段落的不可变引用(越界返回 None)。

Source

pub fn paragraph_mut(&mut self, idx: usize) -> Option<&mut Paragraph>

取第 idx 个段落的可变引用(越界返回 None)。

Source

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

新增一个空段落并返回其可变引用。

对应 TextFrame.add_paragraph()

Source

pub fn add_paragraph_with_text(&mut self, text: &str) -> &mut Paragraph

新增一个带文本的段落,返回其可变引用。

文本按 \n 切分为多段,与 python-pptx 的 TextFrame.text = "a\nb" 行为对齐。

Source

pub fn remove_paragraph(&mut self, idx: usize) -> Option<Paragraph>

移除第 idx 个段落。

Source

pub fn clear(&mut self)

清空段落(保留一个空段,对应 python-pptx TextFrame.clear() 语义)。

Source

pub fn set_text(&mut self, text: &str)

整体替换文本(按 \n 切分为多段,丢弃原段落属性)。

对应 python-pptx text_frame.text = "a\nb"

Source

pub fn auto_size(&self) -> MsoAutoSize

自动调整策略(TextFrame.auto_size)。

Source

pub fn set_auto_size(&mut self, v: MsoAutoSize)

设置自动调整策略。

Source

pub fn vertical_anchor(&self) -> Option<MsoAnchor>

垂直对齐(TextFrame.vertical_anchor)。

Source

pub fn set_vertical_anchor(&mut self, v: MsoAnchor)

设置垂直对齐。

Source

pub fn word_wrap(&self) -> Option<bool>

是否自动换行(TextFrame.word_wrap)。

返回 None 表示走默认值 / 继承。

Source

pub fn set_word_wrap(&mut self, v: bool)

设置是否自动换行。

Source

pub fn margin_left(&self) -> Option<Emu>

左边距(EMU)。

Source

pub fn margin_right(&self) -> Option<Emu>

右边距。

Source

pub fn margin_top(&self) -> Option<Emu>

上边距。

Source

pub fn margin_bottom(&self) -> Option<Emu>

下边距。

Source

pub fn set_margins(&mut self, left: Emu, top: Emu, right: Emu, bottom: Emu)

一次性设置四向边距。

Source

pub fn set_margin_left(&mut self, emu: Emu)

设置左边距。

Source

pub fn set_margin_right(&mut self, emu: Emu)

设置右边距。

Source

pub fn set_margin_top(&mut self, emu: Emu)

设置上边距。

Source

pub fn set_margin_bottom(&mut self, emu: Emu)

设置下边距。

Source

pub fn num_cols(&self) -> Option<u32>

文本列数(numCol 属性)。

返回 None 表示未设置(默认单列);Some(1) 等价于单列。

Source

pub fn set_num_cols(&mut self, count: u32)

设置文本列数。

Source

pub fn col_spacing(&self) -> Option<Emu>

列间距(spcCol 属性,EMU)。

Source

pub fn set_col_spacing(&mut self, emu: Emu)

设置列间距。

Trait Implementations§

Source§

impl Clone for TextBody

Source§

fn clone(&self) -> TextBody

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBody

Source§

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

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

impl Default for TextBody

Source§

fn default() -> TextBody

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

impl<'a> From<&'a mut TextBody> for TextFrame<'a>

Source§

fn from(b: &'a mut TextBody) -> TextFrame<'a>

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V