主题
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):
参数列表
参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
range | str | 空字符串 | 工作表中的选区描述。 |
sheet_name | str|list[str] | 空字符串 | 写入数据的选区所在的工作表名称。 |
book_url | str | 字符串 | 指定写入的表格文件地址。 必须为金山文档云文档地址。 默认当前表格。 |
entire_row | bool | False | 是否删除整行 |
entire_column | bool | False | 是否删除整列 |
xl_shift_to_left | bool | False | 是否向左合并,如果为 False 则向上合并 |
start_row | int | 空值 | 工作表中的起始行(从0 开始),如果不传start_column 则删除整行 |
start_column | int | 空值 | 工作表中的起始列(从0 开始),如果不传start_row 则删除整列 |
drop_sheet | bool | False | 是否删除整个工作表 |
示例
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)