将工作表从一个电子表格复制到另一个电子表格

发布于 2024-07-24 06:48:48 字数 1376 浏览 12 评论 0原文

是否可以使用 gdata API 将电子表格或工作表从一个电子表格复制到另一个电子表格? 现在,我将所有单元格从一个工作表复制到另一个工作表。 每个请求一个单元格。 太慢了。 我读到“细胞批处理”并编写了这段代码:


src_key = 'rFQqEnFWuR6qoU2HEfdVuTw'; dst_key = 'rPCVJ80MHt7K2EVlXNqytLQ'

sheetcl = gdata.spreadsheet.service.SpreadsheetsService('[email protected]','p')
dcs = gdata.docs.service.DocsService('[email protected]', 'p')

src_worksheets = sheetcl.GetWorksheetsFeed(src_key)
dst_worksheets = sheetcl.GetWorksheetsFeed(dst_key)

for src_worksheet, dst_worksheet in zip(src_worksheets.entry, dst_worksheets.entry):

    sheet_id = src_worksheet.id.text.split('/')[-1]
    dst_sheet_id = dst_worksheet.id.text.split('/')[-1]

    cells_feed = sheetcl.GetCellsFeed(src_key, sheet_id)
    dst_cells_feed = sheetcl.GetCellsFeed(dst_key, dst_sheet_id)

    for cell in cells_feed.entry:
        dst_cells_feed.AddInsert(cell)

    sheetcl.ExecuteBatch(dst_cells_feed, dst_cells_feed.GetBatchLink().href)

但它不起作用。 我认为原因是内循环中的每个单元格都有其 id,其中包含电子表格 id:


>>> cell.id.text
'http://spreadsheets.google.com/feeds/cells/rFQqEnFWuR6qoU2HEfdVuTw/default/private/full/R1C1'
>>> 

Is it possible to copy spreadsheets with gdata API or worksheets from one spreadsheet to other? For now i copy all cells from one worksheet to another. One cell per request. It is too slow. I read about "cell batch processing" and write this code:


src_key = 'rFQqEnFWuR6qoU2HEfdVuTw'; dst_key = 'rPCVJ80MHt7K2EVlXNqytLQ'

sheetcl = gdata.spreadsheet.service.SpreadsheetsService('[email protected]','p')
dcs = gdata.docs.service.DocsService('[email protected]', 'p')

src_worksheets = sheetcl.GetWorksheetsFeed(src_key)
dst_worksheets = sheetcl.GetWorksheetsFeed(dst_key)

for src_worksheet, dst_worksheet in zip(src_worksheets.entry, dst_worksheets.entry):

    sheet_id = src_worksheet.id.text.split('/')[-1]
    dst_sheet_id = dst_worksheet.id.text.split('/')[-1]

    cells_feed = sheetcl.GetCellsFeed(src_key, sheet_id)
    dst_cells_feed = sheetcl.GetCellsFeed(dst_key, dst_sheet_id)

    for cell in cells_feed.entry:
        dst_cells_feed.AddInsert(cell)

    sheetcl.ExecuteBatch(dst_cells_feed, dst_cells_feed.GetBatchLink().href)

But it doesn't work. As I suppose reason is that each cell in inner loop has its id which consist of spreadsheet_id:


>>> cell.id.text
'http://spreadsheets.google.com/feeds/cells/rFQqEnFWuR6qoU2HEfdVuTw/default/private/full/R1C1'
>>> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2024-07-31 06:48:48

您可能应该使用单元格范围查询来一次获取整行,然后插入行 在目标电子表格中。

You probably should be using a cell range query to get a whole row at a time, then inserting rows in the target spreadsheet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文