Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 将Google应用程序脚本从打印数组从活动单元格更改为特定的工作表和范围_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 将Google应用程序脚本从打印数组从活动单元格更改为特定的工作表和范围

Google apps script 将Google应用程序脚本从打印数组从活动单元格更改为特定的工作表和范围,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我试图找出如何告诉脚本打印到一个名为“Creative”的特定工作表,并从单元格B2开始。我没有打印代码,而是使用下面的代码。非常感谢你能提供的任何帮助 function getFileArray(folderId){ var folder = DriveApp.getFolderById(folderId); var files = folder.getFiles(); var fileList = []; //Loop though files and add name

我试图找出如何告诉脚本打印到一个名为“Creative”的特定工作表,并从单元格B2开始。我没有打印代码,而是使用下面的代码。非常感谢你能提供的任何帮助



function getFileArray(folderId){
  var folder = DriveApp.getFolderById(folderId);
  var files = folder.getFiles();
  var fileList = [];

  //Loop though files and add names and urls to the array
  while (files.hasNext()){ 
    var file = files.next();
    var fileName = file.getName();    
    var fileUrl = file.getUrl();
    fileList = fileList.concat([[fileName, fileUrl]]);
  }
   //See returned fileList in a log
  //Logger.log( fileList ) //Preview Returned Array      
  return fileList


}


//Prints any 2D array to a range that starts with the selected cell

function printArrayToSelection(twoDimArr){  
  var firstCell = SS.getActiveCell();
  var lastCell = firstCell.offset(twoDimArr.length - 1, twoDimArr[0].length - 1);
  var destinationRange = SS.getActiveSheet().getRange(
    firstCell.getA1Notation() + ':' + lastCell.getA1Notation());
  destinationRange.setValues(twoDimArr);

}

//Print the actual data
function printFileArray(){
  printArrayToSelection(getFileArray('FOLDERIDHERE'));
} 

要为目标范围指定图纸,可以使用getSheetByName方法并将Creative作为参数传递

要获取目标范围,我建议使用getRange方法并将行、列、行数和列数作为参数传递。对于您的情况,这将是2,2,twoDimArr.length,twoDimArr[0].length

此方法的文档可在此处找到:


@布莱恩:没问题。如果您对这个解决方案感到满意,如果您能将此答案标记为有用并接受它,我将不胜感激。我接受了答案,但我的代表太低,无法将其标记为有用。一旦我有15个代表,我会回到这里!
function printArrayToSelection(twoDimArr){  
  var firstCell = SS.getActiveCell();
  var lastCell = firstCell.offset(twoDimArr.length - 1, twoDimArr[0].length - 1);
  var destinationRange = SS.getSheetByName("Creative").getRange(2, 2, twoDimArr.length, twoDimArr[0].length);
  destinationRange.setValues(twoDimArr);
}