在这种情况下,有什么方法可以减少电子表格的计算时间吗?makecopy()?
我有一个工作脚本,其中包含以下代码的自定义类方法:
destination = this
._source
.makeCopy(
this._name,
this._folder
)
.setStarred(true);
此脚本大约需要15秒钟才能完成。 this._source
是driveapp.file的实例(driveapp.getFilebyId('xxxxxxxxxxxxxxxxxxx')
)用户正在使用。 this._name
只是通过将年份贴在标题上而创建的字符串。 'this._folder'是driveapp.folder(driveapp.getFolderByid('xxxxxxxxxxxxxxx')
)的实例。除destination
外,所有这些都在我的开放式触发器中实例化时就进行了实例这种方法(尽管我测量了该实例非常快)。
在此说法之前和之后,我测量了15380毫秒。我隔离了driveapp.file.setstarred()
并测量100毫秒,因此问题归结为driveapp.file.makecopy()
。我可以做些什么来获得更快的结果?我尝试了各种版本的.makecopy
,它们似乎都花了一段时间。我认为问题是我的实际文件的大小(178 kb,我认为这对于床单文件来说很大)。它有13张床单,一张收入数量,一张收入数量,而现金抽屉,保险箱和银行存款/提款的每日核对十二个月,因此其中有无数的配方。
I have a working script that contains the following code in a method of a custom class:
destination = this
._source
.makeCopy(
this._name,
this._folder
)
.setStarred(true);
This script is taking approximately 15 seconds to complete. this._source
is an instance of DriveApp.File (DriveApp.getFileById('xxxxxxxxxxxx')
) of the template file the user is working with. this._name
is simply a string created by tacking the year onto the title. 'this._folder' is an instance of DriveApp.Folder (DriveApp.getFolderById('xxxxxxxxxxxx')
). All of these except for destination
are instantiated when the class is instantiated in my On Open trigger, long before the user begins making the copy, while destination
is instantiated at the beginning of this method (though I measured that instantiation to be pretty fast).
I measured 15380 milliseconds before and after this statement. I isolated DriveApp.File.setStarred()
and measured 100 milliseconds, so the problem is down to DriveApp.File.makeCopy()
. Is there anything I can do to get a faster result? I tried the various versions of .makeCopy
, and they all seemed to take a while. I think the problem is the size of my actual file (178 KB, which I believe is fairly large for a Sheets file). It has 13 Sheets, one for the entire year's revenue numbers, and twelve months of daily reconciliation for cash drawers, the safe, and bank deposits/withdrawals, so it has a myriad of formulas in it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
建议:
您可以尝试 drive drive api api v2文件:复制方法。最初在280KB的文件文件上对此进行了测试,该文件使用API Explorer在计算时间内导致11000毫秒。
SUGGESTION:
You could try Drive API V2 Files:copy method. Initially tested this on a 280kb sheets file which resulted in 11000 milliseconds in computation time using the API Explorer.
不知道它是否一直更快,但对我来说似乎更快
Not sure if it's faster all of the time but it seems faster to me