[英]Google Script - Copy Data from one Workbook To Another - importrange() Alternative
Recently, I have been seeing more and more failures of importrange() on various workbooks so i am toying with the idea of setting up a script to copy data from one sheet to another and put the script on a timer. 最近,我在各种工作簿上看到越来越多的importrange()失败,所以我想要设置一个脚本将数据从一个工作表复制到另一个工作表并将脚本放在一个计时器上。 The trouble is, even though its not a lot of data, it still exceeds the maximum execution time. 麻烦的是,即使它不是很多数据,它仍然超过了最大执行时间。 Any thoughts on how i can resolve this (Besides making the range smaller and processing smaller chunks of data)? 关于如何解决这个问题的任何想法(除了使范围更小并处理更小的数据块)? Here is my code: 这是我的代码:
function CopyData() {
//Clear DataSheet
SpreadsheetApp.openById('12ZS...').getSheetByName('DataSheet').getRange('A:C').clearContent();
//Copy new database data
var SData = SpreadsheetApp.openById('1cnNN...').getSheetByName('QuoteCounts').getRange('M1:O5000').getValues();
SpreadsheetApp.openById('12ZS...').getSheetByName('DataSheet').getRange('A1:C5000').setValues(SData);
}
Try this: 尝试这个:
function CopyData() {
var ss=SpreadsheetApp.openById('12ZS...')
ss.getSheetByName('DataSheet').getRange('A:C').clearContent();
var SData = SpreadsheetApp.openById('1cnNN...').getSheetByName('QuoteCounts').getRange('M1:O5000').getValues();
ss.getSheetByName('DataSheet').getRange(1,1,SData.length,SData[0].length).setValues(SData);
}
You could also do it this way: 你也可以这样做:
function CopyData() {
var ss=SpreadsheetApp.openById('12ZS...')
ss.getSheetByName('DataSheet').getRange('A:C').clearContent();
var sdrg=SpreadsheetApp.openById('1cnNN...').getSheetByName('QuoteCounts').getRange('M1:O5000');
var SData =sdrg.getValues();
ss.getSheetByName('DataSheet').getRange(1,1,sdrg.getHeight(),sdrg.getWidth()).setValues(SData);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.