pub struct SharedStringsTable { /* private fields */ }Expand description
共享字符串表。
对应 xl/sharedStrings.xml 的 <sst> 根元素。
Implementations§
Sourcepub fn add(&mut self, s: impl Into<String>) -> usize
pub fn add(&mut self, s: impl Into<String>) -> usize
添加一个字符串,返回其索引。
如果字符串已存在,返回已有索引(不重复存储);
否则追加到末尾,返回新索引。
同时 reference_count +1(每次调用都视为一次引用)。
Sourcepub fn index_of(&self, s: &str) -> Option<usize>
pub fn index_of(&self, s: &str) -> Option<usize>
仅查询字符串的索引(不增加引用计数)。
如果字符串已存在,返回 Some(索引);否则返回 None。
Sourcepub fn unique_count(&self) -> usize
pub fn unique_count(&self) -> usize
唯一字符串数(uniqueCount)。
Sourcepub fn to_xml(&self) -> String
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>Sourcepub fn from_xml(xml: &str) -> Result<Self>
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§fn clone(&self) -> SharedStringsTable
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§fn default() -> SharedStringsTable
fn default() -> SharedStringsTable
Returns the “default value” for a type. Read more
Auto Trait Implementations§
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