Workbook 接口
工作簿接口代表管理工作表、样式和工作簿级别设置的工作簿对象。
类
-
class oo::iWorkbook
管理工作表、命名样式和工作簿属性的主要工作簿接口。
日期和引用设置
-
bool is_date1904() const
检查工作簿是否使用 1904 日期系统。
- 返回:
使用 1904 日期系统返回 true,使用 1900 日期系统返回 false
-
void set_date1904(bool set = true)
设置工作簿使用的日期系统。
- 参数:
set -- true 使用 1904 日期系统,false 使用 1900 日期系统
-
bool is_a1_ref_mode() const
检查工作簿是否使用 A1 引用模式。
- 返回:
使用 A1 引用模式返回 true,使用 R1C1 模式返回 false
-
void set_a1_ref_mode(bool a1_mode = true)
设置工作簿的引用模式。
- 参数:
a1_mode -- true 使用 A1 引用模式,false 使用 R1C1 模式
计算设置
-
CalcTypeEnum get_calc_mode() const
获取工作簿的计算模式。
- 返回:
当前计算模式
-
void set_calc_mode(CalcTypeEnum type)
设置工作簿的计算模式。
- 参数:
type -- 要设置的计算模式
工作表管理
-
iWorksheet *add_worksheet(const char *name = nullptr)
向工作簿添加新工作表。
- 参数:
name -- 新工作表的可选名称(为空时自动生成工作表名称)
- 返回:
指向新工作表的指针,失败返回 nullptr
-
iWorksheet *insert_worksheet(int index, const char *name = nullptr)
在指定位置插入工作表。
- 参数:
index -- 插入工作表的位置(0-based)
name -- 新工作表的可选名称
- 返回:
指向新工作表的指针,失败返回 nullptr
-
void shift_sheet(int srcIdx, int dstIdx)
将工作表从一个位置移动到另一个位置。
- 参数:
srcIdx -- 源索引(0-based)
dstIdx -- 目标索引(0-based)
-
void delete_sheet(int index)
从工作簿中删除工作表。
- 参数:
index -- 要删除的工作表索引(0-based)
工作表信息
-
int sheet_count() const
获取工作簿中的工作表数量。
- 返回:
工作表数量
-
iWorksheet *get_sheet(int index) const
按索引获取工作表。
- 参数:
index -- 工作表索引(0-based)
- 返回:
指向工作表的指针,索引无效返回 nullptr
-
SheetTypeEnum sheet_type(int index) const
获取工作表的类型。
- 参数:
index -- 工作表索引(0-based)
- 返回:
工作表的类型
-
SheetStateEnum get_sheet_state(int index) const
获取工作表的可见性状态。
- 参数:
index -- 工作表索引(0-based)
- 返回:
工作表的可见性状态
-
void set_sheet_state(int index, SheetStateEnum state = SHEETSTATE_HIDDEN)
设置工作表的可见性状态。
- 参数:
index -- 工作表索引(0-based)
state -- 新的可见性状态
工作表命名
-
const char *sheet_name(int index) const
获取工作表的名称。
- 参数:
index -- 工作表索引(0-based)
- 返回:
工作表的名称
-
void rename_sheet(int index, const char *newname)
重命名工作表。
- 参数:
index -- 工作表索引(0-based)
newname -- 工作表的新名称
活动工作表管理
-
int get_active_sheet() const
获取活动工作表的索引。
- 返回:
活动工作表的索引(0-based)
-
bool set_active_sheet(int tab)
设置活动工作表。
- 参数:
tab -- 要激活的工作表索引(0-based)
- 返回:
成功返回 true,索引无效返回 false
定义名称
-
bool set_defined_name(const char *name, const char *expr, const char *local_name = nullptr)
在工作簿中设置定义名称。
- 参数:
name -- 要定义的名称
expr -- 定义名称的公式表达式
local_name -- 本地工作表名称(可选)
- 返回:
成功返回 true
-
int defined_name_num()
在工作簿中设置定义名称。
- 返回:
定义名称的数量
-
const char *get_defined_name(int index, bool *is_local = 0) const
获取定义名称。
- 参数:
index -- 定义名称的索引。
is_local -- 是否为局部定义名称。
- 返回:
定义名称
-
const char *get_local_name(int index) const
获取定义名称所属的工作表。
- 参数:
index -- 定义名称的索引。
- 返回:
工作表命名
-
const char *get_defined_name_expr(int index) const
获取定义名称的表达式。
- 参数:
index -- 定义名称的索引。
- 返回:
表达式字符串
-
void delete_defined_name(int index)
删除定义名称。
- 参数:
index -- 定义名称的索引。
样式管理
-
iStyle *get_named_style(const char *name)
从工作簿获取命名样式。
- 参数:
name -- 要检索的样式名称
- 返回:
指向样式的指针,未找到返回 nullptr
Style 对象创建
-
bool is_date1904() const
使用示例
#include "oosxl.hxx"
using namespace oo;
// Create document and get workbook
Document* doc = create_document();
Workbook* wb = doc->get_workbook();
// Set workbook properties
wb->set_date1904(false); // Use 1900 date system
wb->set_a1_ref_mode(true); // Use A1 reference mode
// Add worksheets
Worksheet* sheet1 = wb->add_worksheet("Data");
Worksheet* sheet2 = wb->add_worksheet("Summary");
// Set active sheet
wb->set_active_sheet(0);
// Create and use styles
Style* header_style = wb->make_normal_style();
header_style->set_bold(true);
header_style->set_font_size(14);