pub struct TableShape { /* private fields */ }Expand description
表格(行优先,行内 cell)。
Implementations§
Source§impl TableShape
impl TableShape
Sourcepub fn new(rows: usize, cols: usize, col_width: Emu, row_height: Emu) -> Self
pub fn new(rows: usize, cols: usize, col_width: Emu, row_height: Emu) -> Self
构造一个指定行列的表格(cell 文本留空)。
Sourcepub fn from_frame(frame: OxmlFrame) -> Self
pub fn from_frame(frame: OxmlFrame) -> Self
从 oxml Frame 构造。
Sourcepub fn set_first_row(&mut self, v: bool)
pub fn set_first_row(&mut self, v: bool)
设置首行特殊格式。
Sourcepub fn set_last_row(&mut self, v: bool)
pub fn set_last_row(&mut self, v: bool)
设置末行特殊格式。
Sourcepub fn first_column(&self) -> bool
pub fn first_column(&self) -> bool
是否启用首列特殊格式(firstColumn="1")。
对标 python-pptx Table.first_column。
Sourcepub fn set_first_column(&mut self, v: bool)
pub fn set_first_column(&mut self, v: bool)
设置首列特殊格式。
Sourcepub fn last_column(&self) -> bool
pub fn last_column(&self) -> bool
是否启用末列特殊格式(lastColumn="1")。
对标 python-pptx Table.last_column。
Sourcepub fn set_last_column(&mut self, v: bool)
pub fn set_last_column(&mut self, v: bool)
设置末列特殊格式。
Sourcepub fn horz_banding(&self) -> bool
pub fn horz_banding(&self) -> bool
是否启用水平条纹(noHBand="0" 表示启用)。
对标 python-pptx Table.horz_banding。
注意:OOXML 中 noHBand="1" 表示禁用,本方法返回取反值(true=启用)。
Sourcepub fn set_horz_banding(&mut self, v: bool)
pub fn set_horz_banding(&mut self, v: bool)
设置水平条纹。
Sourcepub fn vert_banding(&self) -> bool
pub fn vert_banding(&self) -> bool
是否启用垂直条纹(noVBand="0" 表示启用)。
对标 python-pptx Table.vert_banding。
注意:OOXML 中 noVBand="1" 表示禁用,本方法返回取反值(true=启用)。
Sourcepub fn set_vert_banding(&mut self, v: bool)
pub fn set_vert_banding(&mut self, v: bool)
设置垂直条纹。
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。
§示例
use pptx_rs::shape::TableShape;
use pptx_rs::Emu;
let mut t = TableShape::new(2, 2, Emu(1000), Emu(500));
assert!(t.set_style("Medium Style 2 - Accent 1"));
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 table_style(&self) -> Option<&TableStyle>
pub fn table_style(&self) -> Option<&TableStyle>
取表格样式引用。
Sourcepub fn clear_style(&mut self)
pub fn clear_style(&mut self)
清除表格样式引用。
Sourcepub fn cell_text(&self, row: usize, col: usize) -> Option<String>
pub fn cell_text(&self, row: usize, col: usize) -> Option<String>
取 cell 文本(把多段多 Run 拼起来,段间 \n)。
Sourcepub fn cell_mut(&mut self, row: usize, col: usize) -> &mut OxmlCell
pub fn cell_mut(&mut self, row: usize, col: usize) -> &mut OxmlCell
取 cell 可变引用。
对应 python-pptx 中 table.cell(row, col)。包含创建空 cell 的能力(越界会
自动 push),适合“按需扩展“场景。
Sourcepub fn column_width(&self, col: usize) -> Option<Emu>
pub fn column_width(&self, col: usize) -> Option<Emu>
取列宽。
Sourcepub fn row_height(&self, row: usize) -> Option<Emu>
pub fn row_height(&self, row: usize) -> Option<Emu>
取行高。
Sourcepub fn set_header_row(&mut self, row: usize, is_header: bool) -> Result<()>
pub fn set_header_row(&mut self, row: usize, is_header: bool) -> Result<()>
标记某行为表头(首行加粗等特殊样式)。
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
列数。
Sourcepub fn column_mut(&mut self, idx: usize) -> Option<&mut OxmlCol>
pub fn column_mut(&mut self, idx: usize) -> Option<&mut OxmlCol>
整列(可变)。
Sourcepub fn set_cell_fill(&mut self, row: usize, col: usize, c: Color) -> Result<()>
pub fn set_cell_fill(&mut self, row: usize, col: usize, c: Color) -> Result<()>
设 cell 填充色。
对应 python-pptx cell.fill.solid(); cell.fill.fore_color.rgb = ...。
Sourcepub fn set_cell_margins(
&mut self,
row: usize,
col: usize,
top: Emu,
left: Emu,
bottom: Emu,
right: Emu,
) -> Result<()>
pub fn set_cell_margins( &mut self, row: usize, col: usize, top: Emu, left: Emu, bottom: Emu, right: Emu, ) -> Result<()>
设 cell 四向内边距(EMU,顺序 top/left/bottom/right)。
Sourcepub fn cell_text_frame_mut(&mut self, row: usize, col: usize) -> &mut TextBody
pub fn cell_text_frame_mut(&mut self, row: usize, col: usize) -> &mut TextBody
取 cell 文本帧可变引用(cell.text_frame 风格)。
通过 cell_mut 返回 OxmlCell,其 .text 字段就是 TextBody;
调用方需要进一步 .text 访问或用 TextFrame::from(&mut c.text) 包装。
Sourcepub fn add_column(&mut self, width: Emu) -> &mut OxmlCol
pub fn add_column(&mut self, width: Emu) -> &mut OxmlCol
追加新列。
Sourcepub fn remove_row(&mut self, idx: usize) -> Result<()>
pub fn remove_row(&mut self, idx: usize) -> Result<()>
删除指定行。
对标 python-pptx 中通过 XML 操作删除 <a:tr> 的能力。
§参数
idx:行索引(0-based)。
§错误
crate::Error::IndexOutOfRange:idx越界。
Sourcepub fn remove_column(&mut self, idx: usize) -> Result<()>
pub fn remove_column(&mut self, idx: usize) -> Result<()>
Sourcepub fn merge_cells(
&mut self,
row1: usize,
col1: usize,
row2: usize,
col2: usize,
) -> Result<()>
pub fn merge_cells( &mut self, row1: usize, col1: usize, row2: usize, col2: usize, ) -> Result<()>
合并指定矩形区域的单元格。
对标 python-pptx cell.merge(other_cell)。
§参数
row1, col1:合并区域左上角;row2, col2:合并区域右下角。
§行为
- 左上角 cell 设为合并源(
grid_span/row_span); - 区域内其它 cell 设为
h_merge/v_merge虚拟单元格; - 若区域只有 1×1 则为 no-op。
§错误
crate::Error::IndexOutOfRange:索引越界;crate::Error::Other:row2 < row1或col2 < col1。
Sourcepub fn split_cell(&mut self, row: usize, col: usize) -> Result<()>
pub fn split_cell(&mut self, row: usize, col: usize) -> Result<()>
拆分单元格(TODO-029 高阶 API)。
把一个由 Self::merge_cells 合并出的“合并源“单元格还原为
多个独立单元格。与 merge_cells 是逆操作。
§参数
row, col:合并源单元格的位置(即合并时的左上角,必须是grid_span > 1或row_span > 1的“真实“单元格,不能是 h_merge/v_merge 的虚拟单元格)。
§行为
- 把
(row, col)的grid_span/row_span重置为 1; - 把合并区域内的所有虚拟单元格(
h_merge/v_merge为 true)解除虚拟状态; - 单元格的文本/填充/边框等属性不会被重置——只会修改合并相关字段。
§错误
crate::Error::IndexOutOfRange:row/col越界;crate::Error::Other:目标单元格不是合并源(grid_span == 1 && row_span == 1), 或目标单元格是虚拟单元格(h_merge/v_merge为 true)。
Sourcepub fn set_cell_border(
&mut self,
row: usize,
col: usize,
side: BorderSide,
width: Emu,
color: Color,
no_fill: bool,
) -> Result<()>
pub fn set_cell_border( &mut self, row: usize, col: usize, side: BorderSide, width: Emu, color: Color, no_fill: bool, ) -> Result<()>
设置单元格边框。
对标 python-pptx cell.border_top / border_bottom / border_left / border_right。
§参数
row, col:单元格位置;side:边框方向(BorderSide);width:边框宽度(EMU);color:边框颜色(Color::None表示使用主题继承);no_fill:是否写出<a:noFill/>(无填充边框)。
§错误
crate::Error::IndexOutOfRange:row或col越界。
Sourcepub fn cell_border(
&self,
row: usize,
col: usize,
side: BorderSide,
) -> Option<CellBorder>
pub fn cell_border( &self, row: usize, col: usize, side: BorderSide, ) -> Option<CellBorder>
取单元格边框(克隆)。
Sourcepub fn set_placeholder(&mut self, ph_idx: u32, ph_type: Option<&str>)
pub fn set_placeholder(&mut self, ph_idx: u32, ph_type: Option<&str>)
将本表格形状标记为占位符(TODO-007 表格占位符类型化填充)。
写出 XML 时会在 <p:nvGraphicFramePr>/<p:nvPr> 内插入
<p:ph type="tbl" idx="..."/>,使 PowerPoint 把该 graphicFrame
识别为表格占位符的填充实例。
§参数
ph_idx:占位符索引(对应<p:ph idx="..."/>)。ph_type:占位符类型字符串(如"tbl"/"obj"),None时省略type属性。
Sourcepub fn clear_placeholder(&mut self)
pub fn clear_placeholder(&mut self)
清除占位符标记,使本表格形状变为普通 graphicFrame。
Sourcepub fn is_placeholder(&self) -> bool
pub fn is_placeholder(&self) -> bool
是否被标记为占位符。
Trait Implementations§
Source§impl Clone for TableShape
impl Clone for TableShape
Source§fn clone(&self) -> TableShape
fn clone(&self) -> TableShape
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableShape
impl Debug for TableShape
Source§impl Default for TableShape
impl Default for TableShape
Source§fn default() -> TableShape
fn default() -> TableShape
Source§impl Shape for TableShape
impl Shape for TableShape
Source§fn rotation(&self) -> f64
fn rotation(&self) -> f64
表格不支持旋转(OOXML 规范)。调用 Shape::set_rotation 会被忽略。