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

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::core::api_resp::{ApiResponseTrait, ResponseFormat};
5
6#[derive(Serialize, Debug, Default)]
7pub(crate) struct ValueRangeRequest {
8    /// 插入范围,包含 sheetId 与单元格范围两部分,目前支持四种索引方式,详见
9    /// 在线表格开发指南,range所表示的范围需要大于等于values占用的范围。
10    pub(crate) range: String,
11    /// 需要写入的值,如要写入公式、超链接、email、@人等,可详看附录sheet 支持写入数据类型
12    pub(crate) values: Value,
13}
14
15#[derive(Deserialize, Debug, Default)]
16#[allow(dead_code)]
17pub struct ValueRangeResponse {
18    /// 插入维度
19    #[serde(rename = "majorDimension")]
20    pub major_dimension: String,
21    /// 插入范围,包含 sheetId 与单元格范围两部分,目前支持四种索引方式,详见
22    /// 在线表格开发指南,range所表示的范围需要大于等于values占用的范围。
23    pub range: String,
24    /// 需要写入的值,如要写入公式、超链接、email、@人等,可详看附录sheet 支持写入数据类型
25    pub values: Value,
26    /// sheet 的版本号
27    pub revision: i32,
28}
29
30/// 更新数据响应体
31#[derive(Deserialize, Debug)]
32#[allow(dead_code)]
33pub struct UpdateSheetDataResponse {
34    /// spreadsheet 的 token
35    #[serde(rename = "spreadsheetToken")]
36    pub spreed_sheet_token: String,
37    /// 写入的范围
38    #[serde(rename = "tableRange")]
39    pub table_range: String,
40    /// sheet 的版本号
41    pub revision: i32,
42    /// 追加数据的范围、行列数等
43    pub updates: SheetDataUpdates,
44}
45
46impl ApiResponseTrait for UpdateSheetDataResponse {
47    fn data_format() -> ResponseFormat {
48        ResponseFormat::Data
49    }
50}
51
52/// 追加数据的范围、行列数等
53#[derive(Deserialize, Debug)]
54#[allow(dead_code)]
55pub struct SheetDataUpdates {
56    /// spreadsheet 的 token
57    #[serde(rename = "spreadsheetToken")]
58    pub spreed_sheet_token: String,
59    /// 写入的范围
60    #[serde(rename = "updatedRange")]
61    pub updated_range: String,
62    /// 写入的行数
63    #[serde(rename = "updatedRows")]
64    pub updated_rows: i32,
65    /// 写入的列数
66    #[serde(rename = "updatedColumns")]
67    pub updated_columns: i32,
68    /// 写入的单元格总数
69    #[serde(rename = "updatedCells")]
70    pub updated_cells: i32,
71    /// sheet 的版本号
72    pub revision: Option<i32>,
73}
74
75impl ApiResponseTrait for SheetDataUpdates {
76    fn data_format() -> ResponseFormat {
77        ResponseFormat::Data
78    }
79}
80
81/// 值与范围
82#[derive(Deserialize, Debug)]
83#[allow(dead_code)]
84pub struct ReadRangeValueRange {
85    /// 插入维度
86    #[serde(rename = "majorDimension")]
87    pub major_dimension: String,
88    /// 返回数据的范围,为空时表示查询范围没有数据
89    pub range: String,
90    /// sheet 的版本号
91    pub revision: i32,
92    /// 查询得到的值
93    pub values: Value,
94}
95
96#[derive(Debug, Serialize, Default)]
97pub struct CellStyle {
98    /// 字体相关样式
99    pub(crate) font: StyleFont,
100    /// 文本装饰 ,0 默认,1 下划线,2 删除线 ,3 下划线和删除线
101    #[serde(rename = "textDecoration")]
102    pub(crate) text_decoration: Option<i32>,
103    /// 数字格式,详见附录 sheet支持数字格式类型
104    pub(crate) formatter: Option<String>,
105    /// 水平对齐,0 左对齐,1 中对齐,2 右对齐
106    #[serde(rename = "hAlign")]
107    pub(crate) h_align: Option<i32>,
108    #[serde(rename = "vAlign")]
109    /// 垂直对齐, 0 上对齐,1 中对齐, 2 下对齐
110    pub(crate) v_align: Option<i32>,
111    /// 字体颜色
112    #[serde(rename = "foreColor")]
113    pub(crate) fore_color: Option<String>,
114    /// 背景颜色
115    #[serde(rename = "backColor")]
116    pub(crate) back_color: Option<String>,
117    /// 边框类型,可选 "FULL_BORDER","OUTER_BORDER","INNER_BORDER","NO_BORDER","LEFT_BORDER","
118    /// RIGHT_BORDER","TOP_BORDER","BOTTOM_BORDER"
119    #[serde(rename = "borderType")]
120    pub(crate) border_type: Option<String>,
121    /// 边框颜色
122    #[serde(rename = "borderColor")]
123    pub(crate) border_color: Option<String>,
124    /// 是否清除所有格式,默认 false
125    pub(crate) clean: bool,
126}
127
128impl CellStyle {
129    pub fn builder() -> CellStyleBuilder {
130        CellStyleBuilder::default()
131    }
132}
133
134#[derive(Default)]
135pub struct CellStyleBuilder {
136    request: CellStyle,
137}
138
139impl CellStyleBuilder {
140    pub fn font(mut self, font: StyleFont) -> Self {
141        self.request.font = font;
142        self
143    }
144
145    pub fn text_decoration(mut self, text_decoration: i32) -> Self {
146        self.request.text_decoration = Some(text_decoration);
147        self
148    }
149
150    pub fn formatter(mut self, formatter: impl ToString) -> Self {
151        self.request.formatter = Some(formatter.to_string());
152        self
153    }
154
155    pub fn h_align(mut self, h_align: i32) -> Self {
156        self.request.h_align = Some(h_align);
157        self
158    }
159
160    pub fn v_align(mut self, v_align: i32) -> Self {
161        self.request.v_align = Some(v_align);
162        self
163    }
164
165    pub fn fore_color(mut self, fore_color: impl ToString) -> Self {
166        self.request.fore_color = Some(fore_color.to_string());
167        self
168    }
169
170    pub fn back_color(mut self, back_color: impl ToString) -> Self {
171        self.request.back_color = Some(back_color.to_string());
172        self
173    }
174
175    pub fn border_type(mut self, border_type: impl ToString) -> Self {
176        self.request.border_type = Some(border_type.to_string());
177        self
178    }
179
180    pub fn border_color(mut self, border_color: impl ToString) -> Self {
181        self.request.border_color = Some(border_color.to_string());
182        self
183    }
184
185    pub fn clean(mut self, clean: bool) -> Self {
186        self.request.clean = clean;
187        self
188    }
189
190    pub fn build(self) -> CellStyle {
191        self.request
192    }
193}
194
195/// 字体相关样式
196#[derive(Debug, Serialize, Default)]
197pub struct StyleFont {
198    /// 是否加粗
199    bold: Option<bool>,
200    /// 是否斜体
201    italic: Option<bool>,
202    /// 字体大小 字号大小为9~36 行距固定为1.5,如:10pt/1.5
203    #[serde(rename = "fontSize")]
204    font_size: Option<String>,
205    /// 清除 font 格式,默认 false
206    clean: Option<bool>,
207}
208
209impl StyleFont {
210    pub fn builder() -> StyleFontBuilder {
211        StyleFontBuilder::default()
212    }
213}
214
215#[derive(Default)]
216pub struct StyleFontBuilder {
217    font: StyleFont,
218}
219
220impl StyleFontBuilder {
221    pub fn bold(mut self, bold: bool) -> Self {
222        self.font.bold = Some(bold);
223        self
224    }
225
226    pub fn italic(mut self, italic: bool) -> Self {
227        self.font.italic = Some(italic);
228        self
229    }
230
231    pub fn font_size(mut self, font_size: impl ToString) -> Self {
232        self.font.font_size = Some(font_size.to_string());
233        self
234    }
235
236    pub fn clean(mut self, clean: bool) -> Self {
237        self.font.clean = Some(clean);
238        self
239    }
240
241    pub fn build(self) -> StyleFont {
242        self.font
243    }
244}