复制电子表格也会复制所有链接的文件 [英] Copying a spreadsheet copies all linked files as well

查看:84
本文介绍了复制电子表格也会复制所有链接的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用库方法时,我只希望能够复制电子表格及其所有工作表以及所有定义的工作表名称:

I want to be able to only copy the spreadsheet and all it's sheets along with all defined sheet names, when I utilize the library method:

spreadSheet.copy(newSSName);

或者,

myFile.makeCopy(newNameOfFile);

当前,这些方法复制所有链接的表单和表单中使用的脚本.这对于我需要的东西来说是不必要的副作用,并且会导致Drive文件夹中的乱七八糟.有没有一种方法可以快速而有效地做到这一点,而又不必一个又一个地复制单元格?还是唯一的选择?

Currently these methods copy all linked forms and scripts used in the forms. This is an unnecessary side effect for what I need and will result in a large mess in the Drive folder. Is there a way to do this quickly and efficiently without copying cell by cell, sheet by sheet? Or is that the only option?

谢谢.

推荐答案

此解决方法如何?在这种解决方法中,Sheets API用于复制电子表格.对于类电子表格的copy(),类文件和文件的makeCopy():Drive API的副本,复制的电子表格包含绑定脚本和链接形式.所以我想使用Sheets API.此解决方法的流程如下.

How about this workaround? In this workaround, Sheets API is used for copying a Spreadsheet. In the case of copy() of Class Spreadsheet, makeCopy() of Class File and Files: copy of Drive API, the copied spreadsheet includes the bound scripts and linked forms. So I thought to use Sheets API. The flow of this workaround is as follows.

  1. 使用sheetsheets.get检索源电子表格的对象.
  2. 通过使用sheetssheets.create包含检索到的对象来创建新的电子表格.

通过此流程,可以创建复制的电子表格,而不包括绑定的脚本和链接的表单.示例脚本如下.使用此脚本时,请在高级Google服务和API控制台中启用Sheets API.您可以在此处中了解如何启用表格API. >.

By this flow, the copied Spreadsheet without including the bound scripts and linked forms can be created. The sample script is as follows. When you use this script, please enable Sheets API at Advanced Google Services and API console. You can see about how to enable Sheets API at here.

var fileId = "### fileId of source Spreadsheet ###"; // Please set here.
var obj = Sheets.Spreadsheets.get(fileId, {fields: "namedRanges,properties,sheets"});
Sheets.Spreadsheets.create(obj);

注意:

  • 使用此脚本时,请设置源电子表格的fileId.
  • 在Sheets API的电子表格.create上,无法在特定文件夹中创建电子表格.因此,将复制的电子表格创建到根文件夹.如果要在特定文件夹中创建它,请在复制电子表格后将其移动.当然,您可以使用脚本来做到这一点.
  • 如果要包含电子表格的developerMetadata,请将其添加到fields.
  • Note :

    • When you use this script, please set fileId of source Spreadsheet.
    • At spreadsheets.create of Sheets API, the Spreadsheet cannot be created in the specific folder. So the copied Spreadsheet is created to root folder. If you want to create it in the specific folder, please move it after the Spreadsheet was copied. Of course, you can do it using script.
    • If you want to include developerMetadata of Spreadsheet, please add it to fields.
      • copy() of Class Spreadsheet
      • makeCopy() of Class File
      • Files: copy of Drive API
      • Method: spreadsheets.get of Sheets API
      • Method: spreadsheets.create of Sheets API

      如果这不是您想要的,对不起.

      If this was not what you want, I'm sorry.

      这篇关于复制电子表格也会复制所有链接的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆