open_lark/service/cloud_docs/sheets/v3/data_operation/
replace_cells.rs1use 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 impl_executable_builder_owned,
11 service::sheets::v3::{
12 data_operation::{FindCondition, FindReplaceResult},
13 SpreadsheetSheetService,
14 },
15};
16
17#[derive(Serialize, Debug, Default)]
18pub struct ReplaceCellsRequest {
19 #[serde(skip)]
20 api_request: ApiRequest,
21 #[serde(skip)]
22 spreadsheet_token: String,
23 #[serde(skip)]
25 sheet_id: String,
26 find_condition: FindCondition,
28 find: String,
35 replacement: String,
37}
38
39impl ReplaceCellsRequest {
40 pub fn builder() -> ReplaceCellsRequestBuilder {
41 ReplaceCellsRequestBuilder::default()
42 }
43}
44
45#[derive(Default)]
46pub struct ReplaceCellsRequestBuilder {
47 request: ReplaceCellsRequest,
48}
49
50impl ReplaceCellsRequestBuilder {
51 pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
52 self.request.spreadsheet_token = spreadsheet_token.to_string();
53 self
54 }
55
56 pub fn sheet_id(mut self, sheet_id: impl ToString) -> Self {
57 self.request.sheet_id = sheet_id.to_string();
58 self
59 }
60
61 pub fn find(mut self, find: impl ToString) -> Self {
62 self.request.find = find.to_string();
63 self
64 }
65
66 pub fn range(mut self, range: impl ToString) -> Self {
67 self.request.find_condition.range = range.to_string();
68 self
69 }
70
71 pub fn match_case(mut self, match_case: bool) -> Self {
72 self.request.find_condition.match_case = Some(match_case);
73 self
74 }
75
76 pub fn match_entire_cell(mut self, match_entire_cell: bool) -> Self {
77 self.request.find_condition.match_entire_cell = Some(match_entire_cell);
78 self
79 }
80
81 pub fn search_by_regex(mut self, search_by_regex: bool) -> Self {
82 self.request.find_condition.search_by_regex = Some(search_by_regex);
83 self
84 }
85
86 pub fn include_formulas(mut self, include_formulas: bool) -> Self {
87 self.request.find_condition.include_formulas = Some(include_formulas);
88 self
89 }
90
91 pub fn replacement(mut self, replacement: impl ToString) -> Self {
92 self.request.replacement = replacement.to_string();
93 self
94 }
95
96 pub fn build(mut self) -> ReplaceCellsRequest {
97 self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
98 self.request
99 }
100}
101
102impl_executable_builder_owned!(
104 ReplaceCellsRequestBuilder,
105 SpreadsheetSheetService,
106 ReplaceCellsRequest,
107 BaseResponse<ReplaceCellsResponse>,
108 replace_cells
109);
110
111#[derive(Deserialize, Debug)]
113pub struct ReplaceCellsResponse {
114 pub replace_result: FindReplaceResult,
116}
117
118impl ApiResponseTrait for ReplaceCellsResponse {
119 fn data_format() -> ResponseFormat {
120 ResponseFormat::Data
121 }
122}
123
124impl SpreadsheetSheetService {
125 pub async fn replace_cells(
131 &self,
132 request: ReplaceCellsRequest,
133 option: Option<req_option::RequestOption>,
134 ) -> SDKResult<BaseResponse<ReplaceCellsResponse>> {
135 let mut api_req = request.api_request;
136 api_req.api_path = format!(
137 "/open-apis/sheets/v3/spreadsheets/{spreadsheet_token}/sheets/{sheet_id}/replace",
138 spreadsheet_token = request.spreadsheet_token,
139 sheet_id = request.sheet_id
140 );
141 api_req.http_method = reqwest::Method::POST;
142 api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::App];
143
144 let api_resp = crate::core::http::Transport::request(api_req, &self.config, option).await?;
145
146 Ok(api_resp)
147 }
148}