Skip to main content

CustomProperties

Struct CustomProperties 

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

自定义文档属性集合(/docProps/custom.xml)。

对标 python-pptx 中 Presentation.custom_properties(v1.0+)。 存储用户自定义的键值对,PowerPoint 在“文件 → 信息 → 属性 → 高级属性 → 自定义“中显示。

§序列化

to_opc_package 会在 custom_properties 非空时写出 /docProps/custom.xml, 并在 _rels/.rels 中添加 custom-properties 关系。

§示例

use pptx_rs::Presentation;
use pptx_rs::presentation::CustomPropertyValue;

let mut p = Presentation::new().unwrap();
p.custom_properties_mut().set("Project", CustomPropertyValue::Text("Demo".to_string()));
p.custom_properties_mut().set("Version", CustomPropertyValue::Int(42));
p.save("out.pptx").unwrap();

Implementations§

Source§

impl CustomProperties

Source

pub fn new() -> Self

创建空的自定义属性集合。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn len(&self) -> usize

返回条目数。

Source

pub fn set(&mut self, name: impl Into<String>, value: CustomPropertyValue)

设置(或覆盖)一个自定义属性。

§参数
  • name:属性名(不可为空);
  • value:属性值。
Source

pub fn get(&self, name: &str) -> Option<&CustomPropertyValue>

取指定名称的属性值。

Source

pub fn remove(&mut self, name: &str) -> Option<CustomPropertyValue>

移除指定名称的属性。

返回被移除的值(若存在)。

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &CustomPropertyValue)>

返回所有条目的迭代器。

Source

pub fn to_xml(&self) -> String

序列化为 /docProps/custom.xml 的 XML 字符串。

§XML 结构
<Properties xmlns="...custom-properties" xmlns:vt="...docPropsVTypes">
  <property fmtid="{D5CDD505-...}" pid="2" name="Key1">
    <vt:lpwstr>Value1</vt:lpwstr>
  </property>
  ...
</Properties>

pid 从 2 开始(1 保留给 SummaryInformation)。

Source

pub fn from_xml(xml: &str) -> Self

/docProps/custom.xml 的 XML 字符串解析。

§参数
  • xml:custom.xml 的完整内容。
§返回值

解析出的 CustomProperties。解析失败的条目会被跳过(不中断整体解析)。

Trait Implementations§

Source§

impl Clone for CustomProperties

Source§

fn clone(&self) -> CustomProperties

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 CustomProperties

Source§

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

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

impl Default for CustomProperties

Source§

fn default() -> CustomProperties

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