Skip to content

Commit e27325f

Browse files
【企业微信】新增管理表格内容相:new: #3837 【企业微信】微文档(WeDoc)服务新增了三个管理表格内容的 API 接口,包括批量更新表格内容、获取表格行列信息以及获取指定范围的表格数据
1 parent 72fa3b3 commit e27325f

File tree

8 files changed

+815
-0
lines changed

8 files changed

+815
-0
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,53 @@ public interface WxCpOaWeDocService {
7878
* @throws WxErrorException the wx error exception
7979
*/
8080
WxCpDocShare docShare(@NonNull String docId) throws WxErrorException;
81+
82+
/**
83+
* 编辑表格内容
84+
* 该接口可以对一个在线表格批量执行多个更新操作
85+
* <p>
86+
* 注意:
87+
* 1.批量更新请求中的各个操作会逐个按顺序执行,直到全部执行完成则请求返回,或者其中一个操作报错则不再继续执行后续的操作
88+
* 2.每一个更新操作在执行之前都会做请求校验(包括权限校验、参数校验等等),如果校验未通过则该更新操作会报错并返回,不再执行后续操作
89+
* 3.单次批量更新请求的操作数量 <= 5
90+
* <p>
91+
* 请求方式:POST(HTTPS)
92+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/batch_update?access_token=ACCESS_TOKEN
93+
*
94+
* @param request 编辑表格内容请求参数
95+
* @return 编辑表格内容批量更新的响应结果
96+
* @throws WxErrorException the wx error exception
97+
*/
98+
WxCpDocSheetBatchUpdateResponse docBatchUpdate(@NonNull WxCpDocSheetBatchUpdateRequest request) throws WxErrorException;
99+
100+
/**
101+
* 获取表格行列信息
102+
* 该接口用于获取在线表格的工作表、行数、列数等。
103+
* <p>
104+
* 请求方式:POST(HTTPS)
105+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_properties?access_token=ACCESS_TOKEN
106+
*
107+
* @param docId 在线表格的docid
108+
* @return 返回表格行列信息
109+
* @throws WxErrorException
110+
*/
111+
WxCpDocSheetProperties getSheetProperties(@NonNull String docId) throws WxErrorException;
112+
113+
114+
/**
115+
* 本接口用于获取指定范围内的在线表格信息,单次查询的范围大小需满足以下限制:
116+
* <p>
117+
* 查询范围行数 <=1000
118+
* 查询范围列数 <=200
119+
* 范围内的总单元格数量 <=10000
120+
* <p>
121+
* 请求方式:POST(HTTPS)
122+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_range_data?access_token=ACCESS_TOKEN
123+
*
124+
* @param request 获取指定范围内的在线表格信息请求参数
125+
* @return 返回指定范围内的在线表格信息
126+
* @throws WxErrorException
127+
*/
128+
WxCpDocSheetData getSheetRangeData(@NonNull WxCpDocSheetGetDataRequest request) throws WxErrorException;
129+
81130
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,27 @@ public WxCpDocShare docShare(@NonNull String docId) throws WxErrorException {
6363
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
6464
return WxCpDocShare.fromJson(responseContent);
6565
}
66+
67+
@Override
68+
public WxCpDocSheetBatchUpdateResponse docBatchUpdate(@NonNull WxCpDocSheetBatchUpdateRequest request) throws WxErrorException {
69+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_BATCH_UPDATE);
70+
String responseContent = this.cpService.post(apiUrl, request.toJson());
71+
return WxCpDocSheetBatchUpdateResponse.fromJson(responseContent);
72+
}
73+
74+
@Override
75+
public WxCpDocSheetProperties getSheetProperties(@NonNull String docId) throws WxErrorException {
76+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_GET_SHEET_PROPERTIES);
77+
JsonObject jsonObject = new JsonObject();
78+
jsonObject.addProperty("docid", docId);
79+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
80+
return WxCpDocSheetProperties.fromJson(responseContent);
81+
}
82+
83+
@Override
84+
public WxCpDocSheetData getSheetRangeData(@NonNull WxCpDocSheetGetDataRequest request) throws WxErrorException {
85+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_GET_SHEET_RANGE_DATA);
86+
String responseContent = this.cpService.post(apiUrl, request.toJson());
87+
return WxCpDocSheetData.fromJson(responseContent);
88+
}
6689
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package me.chanjar.weixin.cp.bean.oa.doc;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
import com.google.gson.annotations.SerializedName;
7+
8+
import lombok.AllArgsConstructor;
9+
import lombok.Builder;
10+
import lombok.Data;
11+
import lombok.Getter;
12+
import lombok.NoArgsConstructor;
13+
import lombok.Setter;
14+
import lombok.experimental.Accessors;
15+
import me.chanjar.weixin.cp.bean.oa.doc.WxCpDocSheetData.GridData;
16+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
17+
18+
/**
19+
* 编辑表格内容请求
20+
*
21+
* @author zhongying
22+
* @since 2026-01-07
23+
*/
24+
@Data
25+
@Builder
26+
@NoArgsConstructor
27+
@AllArgsConstructor
28+
@Accessors(chain = true)
29+
public class WxCpDocSheetBatchUpdateRequest implements Serializable {
30+
private static final long serialVersionUID = 584565591133421347L;
31+
32+
/**
33+
* 文档的docid.必填
34+
*/
35+
@SerializedName("docid")
36+
private String docId;
37+
38+
/**
39+
* 更新操作列表.必填
40+
*/
41+
@SerializedName("requests")
42+
private List<Request> requests;
43+
44+
/**
45+
* From json wx cp doc sheet batch update request.
46+
*
47+
* @param json the json
48+
* @return the wx cp doc sheet batch update request
49+
*/
50+
public static WxCpDocSheetBatchUpdateRequest fromJson(String json) {
51+
return WxCpGsonBuilder.create().fromJson(json, WxCpDocSheetBatchUpdateRequest.class);
52+
}
53+
54+
/**
55+
* To json string.
56+
*
57+
* @return the string
58+
*/
59+
public String toJson() {
60+
return WxCpGsonBuilder.create().toJson(this);
61+
}
62+
63+
/**
64+
* 更新操作
65+
*/
66+
@Getter
67+
@Setter
68+
public static class Request implements Serializable {
69+
private static final long serialVersionUID = 253933038745894628L;
70+
71+
/**
72+
* 新增工作表
73+
*/
74+
@SerializedName("add_sheet_request")
75+
private AddSheetRequest addSheetRequest;
76+
77+
/**
78+
* 删除工作表请求
79+
*/
80+
@SerializedName("delete_sheet_request")
81+
private DeleteSheetRequest deleteSheetRequest;
82+
83+
/**
84+
* 更新范围内单元格内容
85+
*/
86+
@SerializedName("update_range_request")
87+
private UpdateRangeRequest updateRangeRequest;
88+
89+
/**
90+
* 删除表格连续的行或列
91+
*/
92+
@SerializedName("delete_dimension_request")
93+
private DeleteDimensionRequest deleteDimensionRequest;
94+
95+
/**
96+
* 新增工作表,新增需满足以下限制
97+
* 范围列数 <=200
98+
* 范围内的总单元格数量 <=10000
99+
*/
100+
@Getter
101+
@Setter
102+
public static class AddSheetRequest implements Serializable {
103+
private static final long serialVersionUID = 523704967699486288L;
104+
105+
/**
106+
* 工作表名称
107+
*/
108+
@SerializedName("title")
109+
private String title;
110+
111+
/**
112+
* 新增工作表的初始行数
113+
*/
114+
@SerializedName("row_count")
115+
private int rowCount;
116+
117+
/**
118+
* 新增工作表的初始列数
119+
*/
120+
@SerializedName("column_count")
121+
private int columnCount;
122+
}
123+
124+
/**
125+
* 删除工作表请求
126+
*/
127+
@Getter
128+
@Setter
129+
public static class DeleteSheetRequest implements Serializable {
130+
private static final long serialVersionUID = 767974765396168274L;
131+
132+
/**
133+
* 工作表唯一标识
134+
*/
135+
@SerializedName("sheet_id")
136+
private String sheetId;
137+
}
138+
139+
/**
140+
* 更新范围内单元格内容
141+
*/
142+
@Getter
143+
@Setter
144+
public static class UpdateRangeRequest implements Serializable {
145+
private static final long serialVersionUID = 433859595039061888L;
146+
147+
/**
148+
* 工作表唯一标识
149+
*/
150+
@SerializedName("sheet_id")
151+
private String sheetId;
152+
153+
/**
154+
* 表格数据
155+
*/
156+
@SerializedName("grid_data")
157+
private GridData gridData;
158+
}
159+
160+
/**
161+
* 删除表格连续的行或列
162+
* 注意:
163+
* 1.该操作会导致表格缩表
164+
* 2.删除的范围遵循 左闭右开 ———— [start_index,end_index) ,如果 end_index <= start_index
165+
* 则该请求报错。
166+
*/
167+
@Getter
168+
@Setter
169+
public static class DeleteDimensionRequest implements Serializable {
170+
private static final long serialVersionUID = 107245521502978033L;
171+
172+
/**
173+
* 工作表唯一标识
174+
*/
175+
@SerializedName("sheet_id")
176+
private String sheetId;
177+
178+
/**
179+
* 删除的维度类型.
180+
* ROW:行
181+
* COLUMN:列
182+
*/
183+
@SerializedName("dimension")
184+
private String dimension;
185+
186+
/**
187+
* 删除行列的起始序号(从1开始)
188+
*/
189+
@SerializedName("start_index")
190+
private int startIndex;
191+
192+
/**
193+
* 删除行列的终止序号(从1开始)
194+
*/
195+
@SerializedName("end_index")
196+
private int endIndex;
197+
}
198+
}
199+
}

0 commit comments

Comments
 (0)