Tabledef 接口
Tabledef 接口代表 Excel 表格(也称为列表对象),提供结构化数据管理功能,包括自动筛选、排序和汇总行等特性。
类
-
class oo::iTabledef
管理 Excel 表格的接口,提供结构化数据、格式化和计算功能。
基本属性
-
const char *name() const
获取表格名称。
- 返回:
表格名称
-
void range(int *beginRow, int *beginCol, int *endRow, int *endCol) const
获取表格范围坐标。
- 参数:
beginRow -- 存储起始行索引的指针
beginCol -- 存储起始列索引的指针
endRow -- 存储终止行索引的指针
endCol -- 存储终止列索引的指针
显示和标识
-
const char *display_name() const
获取表格显示名称。
- 返回:
在 Excel 界面中显示的显示名称
-
void set_display_name(const char *name)
设置表格显示名称。
- 参数:
name -- 新的显示名称
-
const char *comment() const
获取表格注释/描述。
- 返回:
表格注释文本
-
void set_comment(const char *comment)
设置表格注释/描述。
- 参数:
comment -- 新的注释文本
列管理
-
const char *col_name(int idx) const
按索引获取列名。
- 参数:
idx -- 列索引(0-based)
- 返回:
列名
-
bool set_col_name(int idx, const char *name)
设置列名。
- 参数:
idx -- 列索引(0-based)
name -- 新的列名
- 返回:
成功返回 true
-
bool insert_col(int idx, const char *colName)
向表格插入新列。
- 参数:
idx -- 插入位置(0-based)
colName -- 新列的名称
- 返回:
成功返回 true
-
void delete_col_by_index(int idx)
按索引删除列。
- 参数:
idx -- 要删除的列索引(0-based)
-
void delete_col(const char *colName)
按名称删除列。
- 参数:
colName -- 要删除的列名
汇总行
-
void set_totals_row_label(const char *label)
设置汇总行的标签。
- 参数:
label -- 汇总行的标签文本
-
void set_display_total(bool show = true)
显示或隐藏汇总行。
- 参数:
show -- true 显示汇总行,false 隐藏
-
TotalsFuncEnum totals_row_func(int column_idx) const
获取列的汇总函数。
- 参数:
column_idx -- 列索引(0-based)
- 返回:
汇总函数类型
-
void set_totals_row_func(int colIndex, TotalsFuncEnum func)
设置列的汇总函数。
- 参数:
colIndex -- 列索引(0-based)
func -- 要应用的汇总函数
表格样式
-
const char *style_name() const
获取表格样式名称。
- 返回:
表格样式名称
-
void set_style_name(const char *style_name)
按名称设置表格样式。
- 参数:
style_name -- 表格样式名称
-
void set_preset_style(int id)
Set a predefined table style with identification code.
- 参数:
id -- 预设样式标识符
-
bool row_strips() const
检查是否启用条纹行。
- 返回:
如果显示条纹行返回 true
-
void set_row_strips(bool strips = true)
启用或禁用条纹行。
- 参数:
strips -- true 显示条纹行,false 显示纯色填充
-
const char *name() const
使用示例
#include "oosxl.hxx"
// Get or create a table
oo::iTabledef* table = worksheet->add_tabledef("SalesData", 1, 0, 10, 3);
// Set column names
table->set_col_name(0, "Date");
table->set_col_name(1, "Product");
table->set_col_name(2, "Quantity");
table->set_col_name(3, "Revenue");
// Configure totals row
table->set_display_total(true);
table->set_totals_row_func(2, TOTALS_FUNC_SUM); // Sum for Quantity
table->set_totals_row_func(3, TOTALS_FUNC_SUM); // Sum for Revenue
// Apply table style
table->set_style_name("TableStyleMedium4");
table->set_row_strips(true);
// Set table properties
table->set_display_name("Quarterly Sales Data");
table->set_comment("Sales data for Q1 2023");
汇总函数参考
函数 |
描述 |
|---|---|
TOTALS_FUNC_NONE |
无汇总计算 |
TOTALS_FUNC_SUM |
值的算术和 |
TOTALS_FUNC_AVERAGE |
值的算术平均值 |
TOTALS_FUNC_COUNT |
非空单元格计数 |
TOTALS_FUNC_COUNT_NUMS |
包含数字的单元格计数 |
TOTALS_FUNC_CUSTOM |
单独提供的自定义公式 |
TOTALS_FUNC_MIN |
列中的最小值 |
TOTALS_FUNC_MAX |
列中的最大值 |
TOTALS_FUNC_STDDEV |
估计标准偏差 |
TOTALS_FUNC_VAR |
估计方差 |
备注
表格名称在工作簿中必须唯一
列操作会自动调整表格范围
汇总行函数仅适用于适当的数据类型
表格样式遵循Excel内置表格样式名称
插入/删除列会影响表格中的所有行