feat: receive params with json

This commit is contained in:
zzs 2025-03-24 14:51:09 +08:00
parent 0385e63e6e
commit 6a853a9e61

View File

@ -170,6 +170,14 @@ def FindTableIndex(table_bookmarks, location_bookmark_name):
return handle_table_index
def InsertRowWithJSON(json_str):
"""
插入行
"""
data = json.loads(json_str)
InsertRow(data["location_bookmark_name"], data["data"], data["start_row_index"])
def InsertRow(location_bookmark_name, data, start_row_index=-1):
"""
表格插入行
@ -222,7 +230,14 @@ def DebugCallInsertRow():
InsertRow("h1", [["1", "2", "3"], ["4", "5", "6"]], 0)
def DeleteRow(location_bookmark_name, start_row_index, delete_row_count):
def DeleteRowWithJSON(json_str):
"""
删除行
"""
data = json.loads(json_str)
DeleteRow(data["location_bookmark_name"], data["start_row_index"], data["delete_row_count"])
def DeleteRow(location_bookmark_name, start_row_index, delete_row_count=-1):
"""
删除表格行
@ -242,8 +257,9 @@ def DeleteRow(location_bookmark_name, start_row_index, delete_row_count):
if start_row_index < 0 or start_row_index >= row_count:
raise ValueError(f"起始行索引 {start_row_index} 超出范围")
if start_row_index + delete_row_count > row_count:
raise ValueError(f"删除行数量 {delete_row_count} 超出范围")
# 如果未指定删除行数或超出范围,则删除剩余所有行
if start_row_index + delete_row_count > row_count or delete_row_count == -1:
delete_row_count = row_count - start_row_index
try:
handle_table.getRows().removeByIndex(start_row_index, delete_row_count)
@ -419,7 +435,9 @@ g_exportedScripts = (
QueryAll,
QueryAllWithJSON,
InsertRow,
InsertRowWithJSON,
DeleteRow,
DeleteRowWithJSON,
DebugCallReplace,
DebugCallReplaceList,
DebugCallInsertRow,