使用Google Drive API和Python,我创建了一个代码,允许我在表单中键入内容并单击提交按钮时,在Google Sheets的特定单元格中创建注释,但它不起作用。
当我查看注释选项卡时,注释已创建,然后显示[原始内容已删除],甚至没有显示单元格已被注释。
有解决办法吗?我创建的代码如下所示。
sheets_service = build('sheets', 'v4', credentials=credentials) drive_service = build('drive', 'v3', credentials=credentials) content = request.form.get('content') comment = drive_service.comments().create( fileId=SPREADSHEET_ID, body={ 'content': content }, fields='id' ).execute()
直接使用Google Sheet API。
from googleapiclient.discovery import build sheets_service = build('sheets', 'v4', credentials=credentials) content = request.form.get('content') # Define the range for the cell range_ = 'Sheet1!A1' comment = { 'content': content, 'location': { 'sheetId': 0, 'rowIndex': 0, 'columnIndex': 0 } } sheets_service.spreadsheets().comments().create( spreadsheetId=SPREADSHEET_ID, body=comment ).execute()
Google Drive API将允许您对文件级别而非单元格级别进行评论