Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,53 @@ public interface WxCpOaWeDocService {
* @throws WxErrorException the wx error exception
*/
WxCpDocShare docShare(@NonNull String docId) throws WxErrorException;

/**
* 编辑表格内容
* 该接口可以对一个在线表格批量执行多个更新操作
* <p>
* 注意:
* 1.批量更新请求中的各个操作会逐个按顺序执行,直到全部执行完成则请求返回,或者其中一个操作报错则不再继续执行后续的操作
* 2.每一个更新操作在执行之前都会做请求校验(包括权限校验、参数校验等等),如果校验未通过则该更新操作会报错并返回,不再执行后续操作
* 3.单次批量更新请求的操作数量 <= 5
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/batch_update?access_token=ACCESS_TOKEN
*
* @param request 编辑表格内容请求参数
* @return 编辑表格内容批量更新的响应结果
* @throws WxErrorException the wx error exception
*/
WxCpDocSheetBatchUpdateResponse docBatchUpdate(@NonNull WxCpDocSheetBatchUpdateRequest request) throws WxErrorException;

/**
* 获取表格行列信息
* 该接口用于获取在线表格的工作表、行数、列数等。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_properties?access_token=ACCESS_TOKEN
*
* @param docId 在线表格的docid
* @return 返回表格行列信息
* @throws WxErrorException
*/
WxCpDocSheetProperties getSheetProperties(@NonNull String docId) throws WxErrorException;


/**
* 本接口用于获取指定范围内的在线表格信息,单次查询的范围大小需满足以下限制:
* <p>
* 查询范围行数 <=1000
* 查询范围列数 <=200
* 范围内的总单元格数量 <=10000
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/spreadsheet/get_sheet_range_data?access_token=ACCESS_TOKEN
*
* @param request 获取指定范围内的在线表格信息请求参数
* @return 返回指定范围内的在线表格信息
* @throws WxErrorException
*/
WxCpDocSheetData getSheetRangeData(@NonNull WxCpDocSheetGetDataRequest request) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,27 @@ public WxCpDocShare docShare(@NonNull String docId) throws WxErrorException {
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpDocShare.fromJson(responseContent);
}

@Override
public WxCpDocSheetBatchUpdateResponse docBatchUpdate(@NonNull WxCpDocSheetBatchUpdateRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_BATCH_UPDATE);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpDocSheetBatchUpdateResponse.fromJson(responseContent);
}

@Override
public WxCpDocSheetProperties getSheetProperties(@NonNull String docId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_GET_SHEET_PROPERTIES);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("docid", docId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpDocSheetProperties.fromJson(responseContent);
}

@Override
public WxCpDocSheetData getSheetRangeData(@NonNull WxCpDocSheetGetDataRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SPREADSHEET_GET_SHEET_RANGE_DATA);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpDocSheetData.fromJson(responseContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package me.chanjar.weixin.cp.bean.oa.doc;

import java.io.Serializable;
import java.util.List;

import com.google.gson.annotations.SerializedName;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.oa.doc.WxCpDocSheetData.GridData;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* 编辑表格内容请求
*
* @author zhongying
* @since 2026-01-07
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpDocSheetBatchUpdateRequest implements Serializable {
private static final long serialVersionUID = 584565591133421347L;

/**
* 文档的docid.必填
*/
@SerializedName("docid")
private String docId;

/**
* 更新操作列表.必填
*/
@SerializedName("requests")
private List<Request> requests;

/**
* From json wx cp doc sheet batch update request.
*
* @param json the json
* @return the wx cp doc sheet batch update request
*/
public static WxCpDocSheetBatchUpdateRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpDocSheetBatchUpdateRequest.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

/**
* 更新操作
*/
@Getter
@Setter
public static class Request implements Serializable {
private static final long serialVersionUID = 253933038745894628L;

/**
* 新增工作表
*/
@SerializedName("add_sheet_request")
private AddSheetRequest addSheetRequest;

/**
* 删除工作表请求
*/
@SerializedName("delete_sheet_request")
private DeleteSheetRequest deleteSheetRequest;

/**
* 更新范围内单元格内容
*/
@SerializedName("update_range_request")
private UpdateRangeRequest updateRangeRequest;

/**
* 删除表格连续的行或列
*/
@SerializedName("delete_dimension_request")
private DeleteDimensionRequest deleteDimensionRequest;

/**
* 新增工作表,新增需满足以下限制
* 范围列数 <=200
* 范围内的总单元格数量 <=10000
*/
@Getter
@Setter
public static class AddSheetRequest implements Serializable {
private static final long serialVersionUID = 523704967699486288L;

/**
* 工作表名称
*/
@SerializedName("title")
private String title;

/**
* 新增工作表的初始行数
*/
@SerializedName("row_count")
private int rowCount;

/**
* 新增工作表的初始列数
*/
@SerializedName("column_count")
private int columnCount;
}

/**
* 删除工作表请求
*/
@Getter
@Setter
public static class DeleteSheetRequest implements Serializable {
private static final long serialVersionUID = 767974765396168274L;

/**
* 工作表唯一标识
*/
@SerializedName("sheet_id")
private String sheetId;
}

/**
* 更新范围内单元格内容
*/
@Getter
@Setter
public static class UpdateRangeRequest implements Serializable {
private static final long serialVersionUID = 433859595039061888L;

/**
* 工作表唯一标识
*/
@SerializedName("sheet_id")
private String sheetId;

/**
* 表格数据
*/
@SerializedName("grid_data")
private GridData gridData;
}

/**
* 删除表格连续的行或列
* 注意:
* 1.该操作会导致表格缩表
* 2.删除的范围遵循 左闭右开 ———— [start_index,end_index) ,如果 end_index <= start_index
* 则该请求报错。
*/
@Getter
@Setter
public static class DeleteDimensionRequest implements Serializable {
private static final long serialVersionUID = 107245521502978033L;

/**
* 工作表唯一标识
*/
@SerializedName("sheet_id")
private String sheetId;

/**
* 删除的维度类型.
* ROW:行
* COLUMN:列
*/
@SerializedName("dimension")
private String dimension;

/**
* 删除行列的起始序号(从1开始)
*/
@SerializedName("start_index")
private int startIndex;

/**
* 删除行列的终止序号(从1开始)
*/
@SerializedName("end_index")
private int endIndex;
}
}
}
Loading