This commit is contained in:
2025-11-06 11:05:22 +08:00
parent 763d9985fa
commit 7860df5c2e
4 changed files with 375 additions and 8 deletions

View File

@@ -263,6 +263,16 @@ public class TencentDocServiceImpl implements ITencentDocService {
log.info("API调用成功原始返回结果: {}", result != null ? result.toJSONString() : "null");
// 检查API响应中的错误码
if (result != null && result.containsKey("code")) {
Integer code = result.getInteger("code");
if (code != null && code != 0) {
String message = result.getString("message");
log.error("腾讯文档API返回错误 - code: {}, message: {}", code, message);
throw new RuntimeException("腾讯文档API错误: " + message + " (code: " + code + ")");
}
}
// 解析数据为统一的简单格式
JSONArray parsedValues = TencentDocDataParser.parseToSimpleArray(result);
log.info("解析后的数据行数: {}", parsedValues != null ? parsedValues.size() : 0);

View File

@@ -336,12 +336,13 @@ public class TencentDocApiUtil {
* @param openId 开放平台用户ID
* @param fileId 文件ID在线表格的唯一标识
* @param sheetId 工作表ID可从表格链接中获取如 ?tab=BB08J2 中的 BB08J2
* @param range 范围,例如 "A1:Z100"行列从0开始遵循左闭右开原则
* @param range 范围,格式startRow,startColumn,endRow,endColumn从0开始例如"0,0,10,26"表示A1Z11
* @param apiBaseUrl API基础地址默认https://docs.qq.com/openapi/spreadsheet/v3
* @return 表格数据JSON格式包含values数组
* @return 表格数据JSON格式包含gridData
*/
public static JSONObject readSheetData(String accessToken, String appId, String openId, String fileId, String sheetId, String range, String apiBaseUrl) {
// V3版本API路径格式/openapi/spreadsheet/v3/files/{fileId}/{sheetId}/{range}
// range格式startRow,startColumn,endRow,endColumn从0开始的索引
String apiUrl = String.format("%s/files/%s/%s/%s", apiBaseUrl, fileId, sheetId, range);
log.info("读取表格数据 - fileId: {}, sheetId: {}, range: {}, apiUrl: {}", fileId, sheetId, range, apiUrl);
return callApi(accessToken, appId, openId, apiUrl, "GET", null);