Skip to content
本页内容

delete_xl() 函数

通过 delete_xl 函数对数据进行删除操作。

函数签名

python
def delete_xl(range: str = "",
              sheet_name: str | list[str] = '',
              book_url: str | None = '',
              entire_row: bool = False,
              entire_column: bool = False,
              xl_shift_to_left: bool = False,
              start_row: int | None = None,
              start_column: int | None = None,
              drop_sheet: bool = False):

参数列表

参数类型默认值说明
rangestr空字符串工作表中的选区描述。
sheet_namestr|list[str]空字符串写入数据的选区所在的工作表名称。
book_urlstr字符串指定写入的表格文件地址。
必须为金山文档云文档地址。
默认当前表格。
entire_rowboolFalse是否删除整行
entire_columnboolFalse是否删除整列
xl_shift_to_leftboolFalse是否向左合并,如果为 False 则向上合并
start_rowint空值工作表中的起始行(从0开始),如果不传start_column则删除整行
start_columnint空值工作表中的起始列(从0开始),如果不传start_row则删除整列
drop_sheetboolFalse是否删除整个工作表

示例

1. 删除工作表某个范围的数据

python
# 原始工作表
# +-------+-----+
# | Name  | Age |
# +-------+-----+
# |  foo  |  1  |
# +-------+-----+
# |  bar  |  2  |
# +-------+-----+
# |  baz  |  3  |
# +-------+-----+

# 删除"B3:B4"区域内的数据
delete_xl(range="B3:B4")

# 删除后的工作表
# +-------+-----+
# | Name  | Age |
# +-------+-----+
# |  foo  |  1  |
# +-------+-----+
# |  bar  |     |
# +-------+-----+
# |  baz  |     |
# +-------+-----+

2. 删除某行或某列数据

python
# 原始工作表
# +-------+-----+
# | Name  | Age |
# +-------+-----+
# |  foo  |  1  |
# +-------+-----+
# |  bar  |  2  |
# +-------+-----+
# |  baz  |  3  |
# +-------+-----+

# 删除第二行
delete_xl(start_row=1)

# 删除后的数工作表
# 第三行向上合并空行,移动到第二行
# +-------+-----+
# | Name  | Age |
# +-------+-----+
# |  foo  |  1  |
# +-------+-----+
# |  baz  |  3  |
# +-------+-----+

3. 删除整个工作表

python
delete_xl(sheet_name="sh1", drop_sheet=True)