This commit is contained in:
2025-11-06 11:54:37 +08:00
parent b8aafa03c7
commit 3448cde99d
4 changed files with 1016 additions and 15 deletions

View File

@@ -375,19 +375,17 @@ public class TencentDocApiUtil {
int rowIndex = position[0];
int colIndex = position[1];
// 构建 updateCells 请求
JSONObject updateCells = new JSONObject();
// 根据官方文档,使用 updateRangeRequest
// 参考https://docs.qq.com/open/document/app/openapi/v3/sheet/batchupdate/request.html#updaterangerequest
JSONObject updateRangeRequest = new JSONObject();
updateRangeRequest.put("sheetId", sheetId);
// 设置范围
JSONObject rangeObj = new JSONObject();
rangeObj.put("sheetId", sheetId);
rangeObj.put("startRowIndex", rowIndex);
rangeObj.put("endRowIndex", rowIndex + 1); // 不包含
rangeObj.put("startColumnIndex", colIndex);
rangeObj.put("endColumnIndex", colIndex + 1); // 不包含
updateCells.put("range", rangeObj);
// 构建 gridData
JSONObject gridData = new JSONObject();
gridData.put("startRow", rowIndex); // 从0开始
gridData.put("startColumn", colIndex); // 从0开始
// 构建单元格数据
// 构建 rows 数组
JSONArray rows = new JSONArray();
JSONObject rowData = new JSONObject();
JSONArray cellValues = new JSONArray();
@@ -399,10 +397,13 @@ public class TencentDocApiUtil {
JSONArray firstRow = valuesArray.getJSONArray(0);
if (!firstRow.isEmpty()) {
String text = firstRow.getString(0);
// 构建单元格数据
JSONObject cellData = new JSONObject();
JSONObject cellValue = new JSONObject();
cellValue.put("text", text);
cellData.put("cellValue", cellValue);
cellValues.add(cellData);
}
}
@@ -410,14 +411,14 @@ public class TencentDocApiUtil {
rowData.put("values", cellValues);
rows.add(rowData);
updateCells.put("rows", rows);
gridData.put("rows", rows);
updateRangeRequest.put("gridData", gridData);
// 构建 requests
// 注意:根据官方文档,请求类型名称必须是 "updateCellsRequest"(以 Request 结尾)
// 参考https://docs.qq.com/open/document/app/openapi/v3/sheet/batchupdate/update.html
JSONArray requests = new JSONArray();
JSONObject request = new JSONObject();
request.put("updateCellsRequest", updateCells); // ✅ 修改为 updateCellsRequest
request.put("updateRangeRequest", updateRangeRequest);
requests.add(request);
// 构建完整请求体