pub struct Table {
pub cols: Vec<Col>,
pub rows: Vec<Row>,
pub tbl_look: TableLook,
pub table_style: Option<TableStyle>,
}Expand description
表格。
Fields§
§cols: Vec<Col>§rows: Vec<Row>§tbl_look: TableLook表格样式查找属性(控制 tblLook)。
table_style: Option<TableStyle>表格样式引用(<a:tableStyleId>)。
None 时不写出 <a:tableStyleId> 元素。
Implementations§
Source§impl Table
impl Table
Sourcepub fn write_xml(&self, w: &mut XmlWriter)
pub fn write_xml(&self, w: &mut XmlWriter)
写 XML(<a:tbl> 嵌在 <a:graphicData uri="..."> 内)。
§OOXML 元素顺序
<a:tbl>
<a:tblPr>...</a:tblPr> ← 必须先写,且不含 `<a:tblGrid>`
<a:tableStyleId>...</a:tableStyleId> ← 可选,紧跟 tblPr 属性后
<a:tblGrid>...</a:tblGrid> ← 列定义(gridCol 列表)
<a:tr>...</a:tr> ← 行(先 cell 后 close)
<a:tc> ← 单元格
<a:txBody>...</a:txBody> ← 文本
<a:tcPr> ← 单元格属性(边距/边框/对齐)
<a:lnL/>/<a:lnR/>/<a:lnT/>/<a:lnB/>
</a:tcPr>
</a:tc>
</a:tr>
...
</a:tbl>Sourcepub fn set_style(&mut self, name: &str) -> bool
pub fn set_style(&mut self, name: &str) -> bool
设置表格样式(按内置样式名称)。
对标 python-pptx Table.apply_style(style_id)。
§参数
name:内置样式名称(如 “Medium Style 2 - Accent 1”)。
§返回值
- 成功设置返回
true; - 名称不在内置注册表中返回
false(table_style保持不变)。
§示例
use ooxml_core::oxml::table::Table;
let mut t = Table::default();
assert!(t.set_style("Medium Style 2 - Accent 1"));
assert_eq!(
t.table_style.as_ref().unwrap().style_id(),
"{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"
);
assert!(!t.set_style("Unknown Style"));Sourcepub fn set_style_id(&mut self, guid: impl Into<String>)
pub fn set_style_id(&mut self, guid: impl Into<String>)
设置表格样式(按原始 GUID)。
用于设置不在内置注册表中的样式(如自定义 tableStyles.xml 中定义的样式)。
§参数
guid:样式 GUID 字符串(如{5C22544A-7EE6-4342-B048-85BDC9FD1C3A})。
Sourcepub fn clear_style(&mut self)
pub fn clear_style(&mut self)
清除表格样式引用。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Table
impl RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnsafeUnpin for Table
impl UnwindSafe for Table
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