work/wedoc/spreadsheet.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 102 CC 7 SCAR 20.8
CC
7
Cov
0%
batch_update
12.0
get_sheet_properties
12.0
get_sheet_range_data
12.0
CRAP 8.0
1 package QQ::weixin::work::wedoc::spreadsheet;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::wedoc::spreadsheet
8
9 =head1 DESCRIPTION
10
11 文档
12
13 =cut
14
15 use strict;
16 use base qw(QQ::weixin::work::wedoc);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '0.10';
23 our @EXPORT = qw/ batch_update
24 get_sheet_properties get_sheet_range_data /;
25
26 =head1 FUNCTION
27
28 编辑文档
29
30 =head2 batch_update(access_token, hash);
31
32 编辑表格内容
33 最后更新:2022/12/10
34
35 =head2 SYNOPSIS
36
37 L<https://developer.work.weixin.qq.com/document/path/97628>
38
39 =head3 请求说明:
40
41 该接口可以对一个在线表格批量执行多个更新操作。
42
43 注意:
44
45 批量更新请求中的各个操作会逐个按顺序执行,直到全部执行完成则请求返回,或者其中一个操作报错则不再继续执行后续的操作。
46 每一个更新操作在执行之前都会做请求校验(包括权限校验、参数校验等等),如果校验未通过则该更新操作会报错并返回,不再执行后续操作。
47 单次批量更新请求的操作数量 <= 5。
48
49 =head4 请求包结构体为:
50
51 {
52 "docid": "DOCID",
53 "requests": [
54 {
55 "add_sheet_request": {...}
56 },
57 {
58 "update_range_request": {...}
59 },
60 {
61 "delete_dimension_request": {...}
62 },
63 {
64 "delete_sheet_request": {...}
65 }
66 ]
67 }
68
69 =head4 参数说明:
70
71 参数 类型 是否必须 说明
72 access_token 是 调用接口凭证
73 docid string 是 文档的docid
74 requests object[] 是 更新操作列表,详见 UpdateRequest
75
76 =head4 权限说明:
77
78 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?)
79 第三方应用需具有“文档”权限
80 代开发自建应用需具有“文档”权限
81
82 =head3 RETURN 返回结果:
83
84 {
85 "errcode": 0,
86 "errmsg": "ok",
87 "data" {
88 "responses": [
89 {
90 "add_sheet_response": {...}
91 },
92 {
93 "update_range_response": {...}
94 },
95 {
96 "delete_dimension_response": {...}
97 },
98 {
99 "delete_sheet_response": {...}
100 }
101 ]
102 }
103 }
104
105 =head4 RETURN 参数说明:
106
107 参数 类型 说明
108 errcode int32 错误码
109 errmsg string 错误码说明
110 data.responses object[] 结果列表,详见UpdateResponse
111
112 =head4 参数详细说明
113
114 L<https://developer.work.weixin.qq.com/document/path/97628#参数详细说明>
115
116 =cut
117
118 sub batch_update {
119 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
120 my $access_token = $_[0];
121 my $json = $_[1];
122 my $ua = LWP::UserAgent->new;
123 $ua->timeout(30);
124 $ua->env_proxy;
125
126 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/batch_update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
127 if ($response->is_success) {
128 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
129 }
130
131 }
132 return 0;
133 }
134
135 =head1 FUNCTION
136
137 获取文档数据
138
139 =head2 get_sheet_properties(access_token, hash);
140
141 获取表格行列信息
142 最后更新:2024/02/04
143
144 =head2 SYNOPSIS
145
146 L<https://developer.work.weixin.qq.com/document/path/97711>
147
148 =head3 请求说明:
149
150 该接口用于获取在线表格的工作表、行数、列数等。
151
152 =head4 请求包结构体为:
153
154 {
155 "docid": "DOCID"
156 }
157
158 =head4 参数说明:
159
160 参数 类型 是否必须 说明
161 access_token 是 调用接口凭证
162 docid string 是 在线表格的docid
163
164 =head4 权限说明:
165
166 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?)
167 第三方应用需具有“文档”权限
168 代开发自建应用需具有“文档”权限
169
170 =head3 RETURN 返回结果:
171
172 {
173 "errcode": 0,
174 "errmsg": "ok",
175 "properties": [
176 {
177 ...
178 }
179 ]
180 }
181
182 =head4 RETURN 参数说明:
183
184 参数 类型 说明
185 errcode int32 错误码
186 errmsg string 错误码说明
187 properties object[](Properties) 工作表属性
188
189 =head4 参数详细说明
190
191 Properties
192 工作表元数据相关的资源描述
193
194 示例
195
196 {
197 "sheet_id", "ABCDE",
198 "title": "XXXXXX",
199 "row_count": 100,
200 "column_count": 100
201 }
202
203 字段名 数据类型 描述
204 sheet_id string 工作表ID,工作表的唯一标识
205 title string 工作表名称
206 row_count uint32 表格的总行数
207 column_count uint32 表格的总列数
208
209 =cut
210
211 sub get_sheet_properties {
212 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
213 my $access_token = $_[0];
214 my $json = $_[1];
215 my $ua = LWP::UserAgent->new;
216 $ua->timeout(30);
217 $ua->env_proxy;
218
219 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_properties?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
220 if ($response->is_success) {
221 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
222 }
223
224 }
225 return 0;
226 }
227
228 =head2 get_sheet_range_data(access_token, hash);
229
230 获取表格数据
231 最后更新:2023/01/06
232
233 =head2 SYNOPSIS
234
235 L<https://developer.work.weixin.qq.com/document/path/97661>
236
237 =head3 请求说明:
238
239 本接口用于获取指定范围内的在线表格信息,单次查询的范围大小需满足以下限制:
240
241 查询范围行数 <=1000
242 查询范围列数 <=200
243 范围内的总单元格数量 <=10000
244
245 =head4 请求包结构体为:
246
247 {
248 "docid": "DOCID",
249 "sheet_id": "AABBCC",
250 "range": "A1:B2"
251 }
252
253 =head4 参数说明:
254
255 参数 类型 是否必须 说明
256 access_token 是 调用接口凭证
257 docid string 是 在线表格唯一标识
258 sheet_id string 是 工作表ID,工作表的唯一标识
259 range string 是 查询的范围,格式遵循 A1表示法
260
261 =head4 权限说明:
262
263 自建应用需配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?)
264 第三方应用需具有“文档”权限
265 代开发自建应用需具有“文档”权限
266
267 =head3 RETURN 返回结果:
268
269 {
270 "errcode": 0,
271 "errmsg": "ok",
272 "data": {
273 "result": {
274 ...
275 }
276 }
277 }
278
279 =head4 RETURN 参数说明:
280
281 参数 类型 说明
282 errcode int32 错误码
283 errmsg string 错误码说明
284 data.result object(GridData) 表格数据
285
286 =head4 参数详细说明
287
288 L<https://developer.work.weixin.qq.com/document/path/97661#参数详细说明>
289
290 =cut
291
292 sub get_sheet_range_data {
293 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
294 my $access_token = $_[0];
295 my $json = $_[1];
296 my $ua = LWP::UserAgent->new;
297 $ua->timeout(30);
298 $ua->env_proxy;
299
300 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_range_data?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
301 if ($response->is_success) {
302 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
303 }
304
305 }
306 return 0;
307 }
308
309 1;
310 __END__