open_lark/service/cloud_docs/sheets/v2/data_operation/
split_cells.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    core::{
5        api_req::ApiRequest,
6        api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
7        constants::AccessTokenType,
8        req_option, SDKResult,
9    },
10    service::sheets::v2::SpreadsheetService,
11};
12
13/// 拆分单元格请求
14#[derive(Serialize, Debug, Default)]
15pub struct SplitCellsRequest {
16    #[serde(skip)]
17    api_request: ApiRequest,
18    #[serde(skip)]
19    spreadsheet_token: String,
20    /// 查询范围,包含 sheetId 与单元格范围两部分,目前支持四种索引方式,详见 在线表格开发指南
21    range: String,
22}
23
24impl SplitCellsRequest {
25    pub fn builder() -> SplitCellsRequestBuilder {
26        SplitCellsRequestBuilder::default()
27    }
28}
29
30#[derive(Default)]
31pub struct SplitCellsRequestBuilder {
32    request: SplitCellsRequest,
33}
34
35impl SplitCellsRequestBuilder {
36    pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
37        self.request.spreadsheet_token = spreadsheet_token.to_string();
38        self
39    }
40
41    /// 查询范围,包含 sheetId 与单元格范围两部分,目前支持四种索引方式,详见 在线表格开发指南
42    pub fn range(mut self, range: impl ToString) -> Self {
43        self.request.range = range.to_string();
44        self
45    }
46
47    pub fn build(mut self) -> SplitCellsRequest {
48        self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
49        self.request
50    }
51}
52
53#[derive(Deserialize, Debug)]
54pub struct SplitCellsResponse {
55    /// spreadsheet 的 token
56    #[serde(rename = "spreadsheetToken")]
57    pub spread_sheet_token: String,
58}
59
60impl ApiResponseTrait for SplitCellsResponse {
61    fn data_format() -> ResponseFormat {
62        ResponseFormat::Data
63    }
64}
65
66impl SpreadsheetService {
67    /// 拆分单元格
68    pub async fn split_cells(
69        &self,
70        request: SplitCellsRequest,
71        option: Option<req_option::RequestOption>,
72    ) -> SDKResult<BaseResponse<SplitCellsResponse>> {
73        let mut api_req = request.api_request;
74        api_req.api_path = format!(
75            "/open-apis/sheets/v2/spreadsheets/{spreadsheet_token}/unmerge_cells",
76            spreadsheet_token = request.spreadsheet_token
77        );
78        api_req.http_method = reqwest::Method::POST;
79        api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::App];
80
81        let api_resp = crate::core::http::Transport::request(api_req, &self.config, option).await?;
82
83        Ok(api_resp)
84    }
85}