删除 quip 电子表格中的行

问题描述 投票:0回答:1

有没有一种方法可以让我们使用 quipclient 从 quip 电子表格中删除一行。同样的,我们可以使用 quipclient 添加一列或一行来 quip 电子表格吗??

谢谢!

我想在每次代码运行时从我的 quip 电子表格中删除某些行。如果不可能,至少创建一个新的电子表格来添加我需要的数据。

python quip
1个回答
0
投票

我尝试过

quipclient
python 库来访问 quip 电子表格并使用 python 代码添加/删除行。

以下是我遵循的步骤,

  1. 创建帐户来调侃
  2. 查看此 quip API 文档:https://quip.com/dev/automation/documentation/current#tag/Authentication
  3. 为了测试,我创建了 个人访问令牌
  4. 下面是Python代码,
from quipclient import QuipClient
from bs4 import BeautifulSoup

client = QuipClient(access_token="your_access_token") # replace your token as per step 3

spreadsheet_id = "LgPAAQ2PIuB4"# replace your Spreadsheet ID
document = client.get_thread(spreadsheet_id)
html_content = document['html']
soup = BeautifulSoup(html_content, 'html.parser')

delete_row_index = 2 # you can mention which row you want to delete
rows = soup.find_all('tr')
if len(rows) > delete_row_index:
    rows[delete_row_index].decompose()

updated_html = str(soup)

# Update the spreadhseet with updated_html using 'edit_document'
response = client.edit_document(thread_id=spreadsheet_id, content=updated_html, format='html')

我已经测试过它可以删除示例电子表格中的行

初始数据:

name    company title
john    google  CTO
rohn    facebook    CEO
lisa    tesla   MD

删除行后,

name    company title
rohn    facebook    CEO
lisa    tesla   MD
© www.soinside.com 2019 - 2024. All rights reserved.