1
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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"表示A1到Z11)
|
||||
* @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);
|
||||
|
||||
Reference in New Issue
Block a user