Skip to main content

TableShape

Struct TableShape 

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

表格(行优先,行内 cell)。

Implementations§

Source§

impl TableShape

Source

pub fn new(rows: usize, cols: usize, col_width: Emu, row_height: Emu) -> Self

构造一个指定行列的表格(cell 文本留空)。

Source

pub fn from_frame(frame: OxmlFrame) -> Self

从 oxml Frame 构造。

Source

pub fn table(&self) -> &OxmlTable

取 oxml Table 引用。

Source

pub fn table_mut(&mut self) -> &mut OxmlTable

取 oxml Table 可变引用。

Source

pub fn dims(&self) -> (usize, usize)

行列数。

Source

pub fn first_row(&self) -> bool

是否启用首行特殊格式(firstRow="1")。

对标 python-pptx Table.first_row

Source

pub fn set_first_row(&mut self, v: bool)

设置首行特殊格式。

Source

pub fn last_row(&self) -> bool

是否启用末行特殊格式(lastRow="1")。

对标 python-pptx Table.last_row

Source

pub fn set_last_row(&mut self, v: bool)

设置末行特殊格式。

Source

pub fn first_column(&self) -> bool

是否启用首列特殊格式(firstColumn="1")。

对标 python-pptx Table.first_column

Source

pub fn set_first_column(&mut self, v: bool)

设置首列特殊格式。

Source

pub fn last_column(&self) -> bool

是否启用末列特殊格式(lastColumn="1")。

对标 python-pptx Table.last_column

Source

pub fn set_last_column(&mut self, v: bool)

设置末列特殊格式。

Source

pub fn horz_banding(&self) -> bool

是否启用水平条纹(noHBand="0" 表示启用)。

对标 python-pptx Table.horz_banding。 注意:OOXML 中 noHBand="1" 表示禁用,本方法返回取反值(true=启用)。

Source

pub fn set_horz_banding(&mut self, v: bool)

设置水平条纹。

Source

pub fn vert_banding(&self) -> bool

是否启用垂直条纹(noVBand="0" 表示启用)。

对标 python-pptx Table.vert_banding。 注意:OOXML 中 noVBand="1" 表示禁用,本方法返回取反值(true=启用)。

Source

pub fn set_vert_banding(&mut self, v: bool)

设置垂直条纹。

Source

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"));
Source

pub fn set_style_id(&mut self, guid: impl Into<String>)

设置表格样式(按原始 GUID)。

用于设置不在内置注册表中的样式(如自定义 tableStyles.xml 中定义的样式)。

§参数
  • guid:样式 GUID 字符串(如 {5C22544A-7EE6-4342-B048-85BDC9FD1C3A})。
Source

pub fn table_style(&self) -> Option<&TableStyle>

取表格样式引用。

Source

pub fn clear_style(&mut self)

清除表格样式引用。

Source

pub fn cell_text(&self, row: usize, col: usize) -> Option<String>

取 cell 文本(把多段多 Run 拼起来,段间 \n)。

Source

pub fn set_cell_text( &mut self, row: usize, col: usize, text: &str, ) -> Result<()>

设 cell 文本(自动新建段落 + Run)。

§错误
Source

pub fn cell_mut(&mut self, row: usize, col: usize) -> &mut OxmlCell

取 cell 可变引用。

对应 python-pptx 中 table.cell(row, col)包含创建空 cell 的能力(越界会 自动 push),适合“按需扩展“场景。

Source

pub fn cell(&self, row: usize, col: usize) -> Option<&OxmlCell>

取 cell 不可变引用。

Source

pub fn set_column_width(&mut self, col: usize, w: Emu) -> Result<()>

设列宽(覆盖 col 处的宽度)。

Source

pub fn column_width(&self, col: usize) -> Option<Emu>

取列宽。

Source

pub fn set_row_height(&mut self, row: usize, h: Emu) -> Result<()>

设行高。

Source

pub fn row_height(&self, row: usize) -> Option<Emu>

取行高。

Source

pub fn set_header_row(&mut self, row: usize, is_header: bool) -> Result<()>

标记某行为表头(首行加粗等特殊样式)。

Source

pub fn row_count(&self) -> usize

行数。

Source

pub fn column_count(&self) -> usize

列数。

Source

pub fn row(&self, idx: usize) -> Option<&OxmlRow>

取整行(不可变)。

Source

pub fn row_mut(&mut self, idx: usize) -> Option<&mut OxmlRow>

取整行(可变)。

Source

pub fn column(&self, idx: usize) -> Option<&OxmlCol>

整列(不可变)。

Source

pub fn column_mut(&mut self, idx: usize) -> Option<&mut OxmlCol>

整列(可变)。

Source

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

Source

pub fn cell_fill(&self, row: usize, col: usize) -> Option<Color>

取 cell 填充色(克隆)。

Source

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

Source

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) 包装。

Source

pub fn add_row(&mut self, height: Emu) -> &mut OxmlRow

追加新行(返回行索引与可变引用)。

列数沿用现有 cols.len()

Source

pub fn add_column(&mut self, width: Emu) -> &mut OxmlCol

追加新列。

Source

pub fn remove_row(&mut self, idx: usize) -> Result<()>

删除指定行。

对标 python-pptx 中通过 XML 操作删除 <a:tr> 的能力。

§参数
  • idx:行索引(0-based)。
§错误
Source

pub fn remove_column(&mut self, idx: usize) -> Result<()>

删除指定列。

同时从每一行中移除对应位置的 cell。

§参数
  • idx:列索引(0-based)。
§错误
Source

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。
§错误
Source

pub fn split_cell(&mut self, row: usize, col: usize) -> Result<()>

拆分单元格(TODO-029 高阶 API)。

把一个由 Self::merge_cells 合并出的“合并源“单元格还原为 多个独立单元格。与 merge_cells 是逆操作。

§参数
  • row, col:合并源单元格的位置(即合并时的左上角,必须是 grid_span > 1row_span > 1 的“真实“单元格,不能是 h_merge/v_merge 的虚拟单元格)。
§行为
  • (row, col)grid_span / row_span 重置为 1;
  • 把合并区域内的所有虚拟单元格(h_merge / v_merge 为 true)解除虚拟状态;
  • 单元格的文本/填充/边框等属性不会被重置——只会修改合并相关字段。
§错误
Source

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/>(无填充边框)。
§错误
Source

pub fn cell_border( &self, row: usize, col: usize, side: BorderSide, ) -> Option<CellBorder>

取单元格边框(克隆)。

Source

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 属性。
Source

pub fn clear_placeholder(&mut self)

清除占位符标记,使本表格形状变为普通 graphicFrame。

Source

pub fn is_placeholder(&self) -> bool

是否被标记为占位符。

Source

pub fn ph_idx(&self) -> Option<u32>

占位符索引(若已标记)。

Source

pub fn ph_type(&self) -> Option<&str>

占位符类型字符串(若已标记)。

Trait Implementations§

Source§

impl Clone for TableShape

Source§

fn clone(&self) -> TableShape

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 TableShape

Source§

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

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

impl Default for TableShape

Source§

fn default() -> TableShape

Returns the “default value” for a type. Read more
Source§

impl Shape for TableShape

Source§

fn rotation(&self) -> f64

表格不支持旋转(OOXML 规范)。调用 Shape::set_rotation 会被忽略。

Source§

fn id(&self) -> u32

形状唯一 ID(在所属 slide 内)。 Read more
Source§

fn set_id(&mut self, id: u32)

设置 ID。
Source§

fn name(&self) -> &str

形状名。
Source§

fn set_name(&mut self, name: String)

设置形状名。
Source§

fn shape_type(&self) -> &'static str

形状类型(如 "text_box" / "picture" / …)。 Read more
Source§

fn left(&self) -> Emu

左上角 x(EMU)。
Source§

fn set_left(&mut self, emu: Emu)

设置左上角 x。
Source§

fn top(&self) -> Emu

左上角 y(EMU)。
Source§

fn set_top(&mut self, emu: Emu)

设置左上角 y。
Source§

fn width(&self) -> Emu

宽(EMU)。
Source§

fn set_width(&mut self, emu: Emu)

设置宽。
Source§

fn height(&self) -> Emu

高(EMU)。
Source§

fn set_height(&mut self, emu: Emu)

设置高。
Source§

fn set_rotation(&mut self, _deg: f64)

设置旋转角度。

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