open_lark/service/cloud_docs/sheets/
mod.rs

1//! 电子表格(Sheets)服务
2//!
3//! 提供飞书电子表格的完整API功能,支持数据读写、格式设置、公式计算等。
4//! 是处理结构化数据和报表的强大工具。
5//!
6//! # API版本
7//!
8//! - **v2**: 基础电子表格操作
9//! - **v3**: 增强功能和高级特性(推荐)
10//!
11//! # 主要功能
12//!
13//! ## V2 版本功能
14//! - 📊 数据读写操作
15//! - 🎨 单元格样式设置
16//! - 🔗 单元格合并拆分
17//! - 📏 行列操作
18//! - 📋 工作表管理
19//!
20//! ## V3 版本功能(更强大)
21//! - 📈 电子表格完整生命周期
22//! - 🔍 数据查找和替换
23//! - 🎯 条件格式化
24//! - ✅ 数据验证规则
25//! - 🔒 单元格保护
26//! - 🖼️ 浮动图片
27//! - 🔽 筛选器和筛选视图
28//!
29//! # 快速开始
30//!
31//! ```rust
32//! use open_lark::prelude::*;
33//!
34//! let client = LarkClient::builder("app_id", "app_secret")
35//!     .with_app_type(AppType::SelfBuild)
36//!     .build();
37//!
38//! // V3 版本 - 创建电子表格
39//! // let create_request = CreateSpreadsheetRequest::builder()
40//! //     .title("销售数据统计")
41//! //     .folder_token("folder_token")
42//! //     .build();
43//! // let spreadsheet = client.sheets.v3.spreadsheet.create(create_request, None).await?;
44//!
45//! // V3 版本 - 写入数据
46//! // let write_request = WriteDataToMultipleRangesRequest::builder()
47//! //     .spreadsheet_token("spreadsheet_token")
48//! //     .value_ranges(vec![...])
49//! //     .build();
50//! // client.sheets.v3.data_operation.write_data_to_multiple_ranges(write_request, None).await?;
51//! ```
52
53use crate::core::{config::Config, trait_system::Service};
54use std::sync::Arc;
55
56/// Sheets API v2版本
57pub mod v2;
58/// Sheets API v3版本
59pub mod v3;
60
61/// 电子表格服务
62///
63/// 聚合所有Sheets相关的API版本,提供统一的电子表格操作接口。
64/// 推荐使用v3版本获得最新功能和最佳性能。
65pub struct SheetsService {
66    config: Config,
67    #[allow(dead_code)] // Reserved for future optimizations
68    config_arc: Arc<Config>,
69    /// Sheets API v2版本服务
70    pub v2: v2::V2,
71    /// Sheets API v3版本服务(推荐)
72    pub v3: v3::V3,
73}
74
75impl SheetsService {
76    /// 创建新的Sheets服务实例
77    ///
78    /// # 参数
79    /// - `config`: 客户端配置
80    pub fn new(config: Config) -> Self {
81        let config_arc = Arc::new(config.clone());
82        Self {
83            config: config.clone(),
84            config_arc: config_arc.clone(),
85            v2: v2::V2::new(config.clone()),
86            v3: v3::V3::new(config.clone()),
87        }
88    }
89
90    /// 使用共享配置(实验性)
91    pub fn new_from_shared(shared: Arc<Config>) -> Self {
92        Self {
93            config: shared.as_ref().clone(),
94            config_arc: shared.clone(),
95            v2: v2::V2::new(shared.as_ref().clone()),
96            v3: v3::V3::new(shared.as_ref().clone()),
97        }
98    }
99}
100
101impl Service for SheetsService {
102    fn config(&self) -> &Config {
103        &self.config
104    }
105
106    fn service_name() -> &'static str {
107        "sheets"
108    }
109
110    fn service_version() -> &'static str {
111        "v3"
112    }
113}