我最近需要这样做。这就是我想出的,简单地将电子表格键和范围硬编码到ahab的myImportRange
函数中
// to be used in the spreadsheet like so: = myScriptedImportRange( GoogleClock() )
// no need to include key or range because they are in the script here
//
// the third parameter - GoogleClock() - triggers an automatic update every minute.
// updated 2011-07-17 (ahab): better regex to strip sheetname of *outer* single quotes
// updated 2013-01-27 (ben) to hard-code key and range
function myScriptedImportRange( ) {
var key = "PUT YOUR DATA_SPREADSHEET_ID IN HERE"
var sheetrange = "PUT YOUR SHEET AND CELL RANGE IN HERE"
var shra = sheetrange.split("!") ;
if (shra.length==1) shra[1]=shra[0], shra[0]="";
var sheetstring = shra[0].replace( /^'(.*)'$/g , "$1") // was: replace( /'/g , "") ; updated 2011-07-17 (ahab)
var rangestring = shra[1]
var source = SpreadsheetApp.openById( key )
if ( sheetstring.length==0 ) sheet = source.getSheets()[0] ;
else sheet = source.getSheetByName( sheetstring ) ;
return sheet.getRange( rangestring ).getValues();
}
在我的情况下,我有一组私有工作表,一个中间工作表使用常规myImportRange
和 VMERGE 与一些 SQL 将私人工作表中的选择组合到中间工作表中,然后是一个公共工作表,它只有一个单元格包含= myScriptedImportRange( GoogleClock() )
请注意,这里有类似的方法:https ://stackoverflow.com/a/11857014
另请注意,ImportRange
当源工作簿打开/未打开时,该功能和相关功能通常会出现不显示导入数据的问题。此处的评论中描述了一种简单的解决方法:https ://stackoverflow.com/a/11786797