Skip to main content

SharedStringsTable

Struct SharedStringsTable 

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

共享字符串表。

对应 xl/sharedStrings.xml<sst> 根元素。

Implementations§

Source§

impl SharedStringsTable

Source

pub fn new() -> Self

构造空表。

Source

pub fn add(&mut self, s: impl Into<String>) -> usize

添加一个字符串,返回其索引。

如果字符串已存在,返回已有索引(不重复存储); 否则追加到末尾,返回新索引。 同时 reference_count +1(每次调用都视为一次引用)。

Source

pub fn index_of(&self, s: &str) -> Option<usize>

仅查询字符串的索引(不增加引用计数)。

如果字符串已存在,返回 Some(索引);否则返回 None

Source

pub fn get(&self, index: usize) -> Option<&str>

按索引获取字符串。

Source

pub fn unique_count(&self) -> usize

唯一字符串数(uniqueCount)。

Source

pub fn count(&self) -> usize

总引用次数(count)。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

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

迭代所有字符串(按索引顺序)。

Source

pub fn to_xml(&self) -> String

序列化为 xl/sharedStrings.xml 的 XML 字符串。

§输出格式
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="..." count="2" uniqueCount="2">
  <si><t>Hello</t></si>
  <si><t>World</t></si>
</sst>
Source

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

xl/sharedStrings.xml 的 XML 字符串解析。

§解析策略

SpreadsheetML 的 <si> 支持两种文本形态:

  • plain text<si><t>Hello</t></si>(单一 <t>);
  • rich text<si><r><rPr>...</rPr><t>He</t></r><r><t>llo</t></r></si> (多个 <r> run,每个 run 携带自己的样式,Phase 2.2 样式系统会用到)。

本实现采用 三标志位状态机in_si / in_r / in_t), 无论 plain 还是 rich,都把 <t> 文本累积到同一个 current, 在 </si> 时把 current 作为整体字符串插入表。 这样既正确处理 plain 文本,也能在 rich text 场景下保留拼接后的纯文本(样式信息丢失,留给 0.2.0)。

§错误
  • Error::Xml:XML 格式错误或文本 unescape 失败;
  • Error::Schema:遇到不符合 SpreadsheetML 规范的元素(保留枚举,当前路径不主动触发)。

Trait Implementations§

Source§

impl Clone for SharedStringsTable

Source§

fn clone(&self) -> SharedStringsTable

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 SharedStringsTable

Source§

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

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

impl Default for SharedStringsTable

Source§

fn default() -> SharedStringsTable

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