1
This commit is contained in:
@@ -29,8 +29,8 @@ public class TencentDocConfig {
|
||||
/** 授权回调地址 */
|
||||
private String redirectUri;
|
||||
|
||||
/** API基础地址 - V3版本(注意:是 /openapi/v3 不是 /open/v3) */
|
||||
private String apiBaseUrl = "https://docs.qq.com/openapi/v3";
|
||||
/** API基础地址 - V3版本(注意:根据文档路径推测应该是 /open/api/v3) */
|
||||
private String apiBaseUrl = "https://docs.qq.com/open/api/v3";
|
||||
|
||||
/** OAuth授权地址 */
|
||||
private String oauthUrl = "https://docs.qq.com/oauth/v2/authorize";
|
||||
|
||||
@@ -264,11 +264,11 @@ public class TencentDocApiUtil {
|
||||
* @param fileId 文件ID(在线表格的唯一标识)
|
||||
* @param sheetId 工作表ID(可从表格链接中获取,如 ?tab=BB08J2 中的 BB08J2)
|
||||
* @param range 范围,例如 "A1:Z100"(行列从0开始,遵循左闭右开原则)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/openapi/v3)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/open/api/v3)
|
||||
* @return 表格数据(JSON格式,包含values数组)
|
||||
*/
|
||||
public static JSONObject readSheetData(String accessToken, String fileId, String sheetId, String range, String apiBaseUrl) {
|
||||
// V3版本API路径格式:/openapi/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}/ranges/{range}
|
||||
// V3版本API路径格式:/open/api/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}/ranges/{range}
|
||||
String apiUrl = String.format("%s/spreadsheets/%s/sheets/%s/ranges/%s", apiBaseUrl, fileId, sheetId, range);
|
||||
log.info("读取表格数据 - fileId: {}, sheetId: {}, range: {}, apiUrl: {}", fileId, sheetId, range, apiUrl);
|
||||
return callApi(accessToken, apiUrl, "GET", null);
|
||||
@@ -284,11 +284,11 @@ public class TencentDocApiUtil {
|
||||
* @param values 要写入的数据,支持两种格式:
|
||||
* 1. 简单二维数组:[["值1", "值2"], ["值3", "值4"]]
|
||||
* 2. V3 API完整格式(包含CellData结构)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/openapi/v3)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/open/api/v3)
|
||||
* @return 写入结果
|
||||
*/
|
||||
public static JSONObject writeSheetData(String accessToken, String fileId, String sheetId, String range, Object values, String apiBaseUrl) {
|
||||
// V3版本API路径格式:/openapi/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}/ranges/{range}
|
||||
// V3版本API路径格式:/open/api/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}/ranges/{range}
|
||||
String apiUrl = String.format("%s/spreadsheets/%s/sheets/%s/ranges/%s", apiBaseUrl, fileId, sheetId, range);
|
||||
|
||||
// 构建V3 API规范的请求体
|
||||
@@ -311,13 +311,13 @@ public class TencentDocApiUtil {
|
||||
* @param fileId 文件ID(在线表格的唯一标识)
|
||||
* @param sheetId 工作表ID(可从表格链接中获取,如 ?tab=BB08J2 中的 BB08J2)
|
||||
* @param values 要追加的数据,二维数组格式,例如:[["值1", "值2"], ["值3", "值4"]]
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/openapi/v3)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/open/api/v3)
|
||||
* @return 追加结果
|
||||
*/
|
||||
public static JSONObject appendSheetData(String accessToken, String fileId, String sheetId, Object values, String apiBaseUrl) {
|
||||
try {
|
||||
// 先获取工作表信息,找到最后一行(V3版本路径)
|
||||
// V3版本API路径格式:/openapi/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}
|
||||
// V3版本API路径格式:/open/api/v3/spreadsheets/{spreadsheetId}/sheets/{sheetId}
|
||||
String infoUrl = String.format("%s/spreadsheets/%s/sheets/%s", apiBaseUrl, fileId, sheetId);
|
||||
log.info("获取工作表信息以追加数据 - apiUrl: {}", infoUrl);
|
||||
|
||||
@@ -366,12 +366,12 @@ public class TencentDocApiUtil {
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @param fileId 文件ID(在线表格的唯一标识)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/openapi/v3)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/open/api/v3)
|
||||
* @return 文件信息(JSON格式,包含metadata、sheets等信息)
|
||||
* 返回格式示例:{ "fileId": "xxx", "metadata": {...}, "sheets": [...] }
|
||||
*/
|
||||
public static JSONObject getFileInfo(String accessToken, String fileId, String apiBaseUrl) {
|
||||
// V3版本API路径格式:/openapi/v3/spreadsheets/{spreadsheetId}
|
||||
// V3版本API路径格式:/open/api/v3/spreadsheets/{spreadsheetId}
|
||||
String apiUrl = String.format("%s/spreadsheets/%s", apiBaseUrl, fileId);
|
||||
log.info("获取文件信息 - fileId: {}, apiUrl: {}", fileId, apiUrl);
|
||||
return callApi(accessToken, apiUrl, "GET", null);
|
||||
@@ -382,12 +382,12 @@ public class TencentDocApiUtil {
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @param fileId 文件ID(在线表格的唯一标识)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/openapi/v3)
|
||||
* @param apiBaseUrl API基础地址(默认:https://docs.qq.com/open/api/v3)
|
||||
* @return 工作表列表(JSON格式,包含所有sheet的properties信息)
|
||||
* 返回格式示例:{ "sheets": [{ "properties": { "sheetId": "xxx", "title": "工作表1", ... } }] }
|
||||
*/
|
||||
public static JSONObject getSheetList(String accessToken, String fileId, String apiBaseUrl) {
|
||||
// V3版本API路径格式:/openapi/v3/spreadsheets/{spreadsheetId}/sheets
|
||||
// V3版本API路径格式:/open/api/v3/spreadsheets/{spreadsheetId}/sheets
|
||||
String apiUrl = String.format("%s/spreadsheets/%s/sheets", apiBaseUrl, fileId);
|
||||
log.info("获取工作表列表 - fileId: {}, apiUrl: {}", fileId, apiUrl);
|
||||
return callApi(accessToken, apiUrl, "GET", null);
|
||||
|
||||
Reference in New Issue
Block a user