在使用gspread模块for python时,如何在googledocs的文本中间添加新的空白行?

2024-04-19 03:00:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在带有insert_rowappend_rowadd_row的8行之后插入一个新的空行示例,但是它们只在工作表的末尾添加一个新行。在

我的问题是如何正确插入行?在

另外,我读到documentation没有找到所需的类。在


Tags: add示例documentationrowinsert末尾append空行
1条回答
网友
1楼 · 发布于 2024-04-19 03:00:17

Worksheet.insert_row()才是正确的选择

请注意,您必须为插入行的位置提供索引。在

至于如何插入一定数量的行,最好使用for循环:

empty_row = ['' for cell in range(Worksheet.col_count)]
insertion_row = 4
number_of_rows = 8
for row in range(number_of_rows):
    Worksheet.insert_row(empty_row,index=insertion_row)

请注意,这将需要进行与要添加的行数相同的API调用,而目前insert_rows函数的速度慢得惊人。在

相关问题 更多 >