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 SpreadsheetApp.getActive()_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script SpreadsheetApp.getActive()

Google apps script SpreadsheetApp.getActive(),google-apps-script,google-sheets,Google Apps Script,Google Sheets,我已经开始了一段构建应用程序的旅程(我不是IT专业人士),我通过将我的应用程序与Google sheets连接得到了一些支持 虽然所有这些工作,我正在寻求一些关于编辑的指导,如果这是可能的。目前,该应用程序将从Google Sheets中提取数据到设备中。正如您在下面的代码中看到的,这是基于工作表中的数据,而不是范围中的数据。有没有可能改变这一点,以便我可以将所有查找数据存储在一个工作表和范围内,我有更多的内容要添加,最终可能会有许多工作表包含最少的数据 if ( e.parameter.fun

我已经开始了一段构建应用程序的旅程(我不是IT专业人士),我通过将我的应用程序与Google sheets连接得到了一些支持

虽然所有这些工作,我正在寻求一些关于编辑的指导,如果这是可能的。目前,该应用程序将从Google Sheets中提取数据到设备中。正如您在下面的代码中看到的,这是基于工作表中的数据,而不是范围中的数据。有没有可能改变这一点,以便我可以将所有查找数据存储在一个工作表和范围内,我有更多的内容要添加,最终可能会有许多工作表包含最少的数据

if ( e.parameter.func == "static" ) {
  var ss = SpreadsheetApp.getActive();
  var shFlr = ss.getSheetByName("Floors").getDataRange().getValues();
  var shRm = ss.getSheetByName("Rooms").getDataRange().getValues();
  var shItm = ss.getSheetByName("Items").getDataRange().getValues();
  var shCnd = ss.getSheetByName("Condition").getDataRange().getValues();
  var shBldg = ss.getSheetByName("Buildings").getDataRange().getValues();
  var shUOM = ss.getSheetByName("UOM").getDataRange().getValues();//Projects Added
  return ContentService.createTextOutput(JSON.stringify({"UOM":shUOM,"Buildings":shBldg,"Floors":shFlr,"Rooms":shRm,"Items":shItm,"Condition":shCnd,})).setMimeType(ContentService.MimeType.JSON);
如果有人能描述我是如何编辑这篇文章的,我将不胜感激。

试试这个:

function myfunction() {
  const ss=SpreadsheetApp.getActive();
  const shts=["Floors","Rooms","Items","Condtion","Buildings","UOM"];//These are the names of the individual sheets and there order determine the header location for each individual sheet.
  var sh=ss.getSheetByName('Combined');//I named the sheet Combined you can name it whatever you wish
  if(!sh) {var sh=ss.insertSheet('Combined');}//This creates the sheet if it's not already there
  sh.clear();//this clears the combined sheet
  sh.appendRow(shts);//This puts the header titles on the combined sheet
  shts.forEach(function(name,i){
    var s=ss.getSheetByName(name);//This gets the individual sheets
    var v=s.getRange(1,1,s.getLastRow(),1).getValues();//this gets each sheets one column of data
    sh.getRange(2,i+1,v.length,1).setValues(v);//this puts the data into each column of the combined sheet under that sheets name
  });
}

我根本没有调试过这个。因此,您可能需要调试它。我知道你希望它能起作用……我也是。

我不清楚你在问什么。您的数据存储在工作表中的各个范围内。嗨,Cooper,每个列表(楼层、房间、项目)都列在单独的工作表上,我希望所有这些都列在一张工作表上(可能称为“项目”)。我可以这样做,但我需要一些关于脚本部分的指导。我的计划是这样的:图纸名称=项目楼层在A1:A20房间在B1:20项目在C1:20中显示数据输入了吗?在图纸中手动输入。这些是仅用于应用程序的查找值。可以提供当前工作表和预期最终工作表的图像吗?谢谢Cooper,将数据放在一张工作表上不是问题,因为这些是非常小的列表,我可以对这些进行c&p,而无需发布。这些列表是主数据,是应用程序中的选择列表。我正在尝试编辑我的脚本,这样它就不会基于选项卡/工作表来提取数据,而是必须来自一个单一的工作表,在这个工作表中,我将所有这些数据都放在一个选项卡/工作表中。下面的脚本基于各种名称的工作表中的数据。
if(e.parameter.func==“static”){var ss=SpreadsheetApp.getActive();var shFlr=ss.getSheetByName(“楼层”).getDataRange().getValues();//工作表名称应为ProjectSetUp,并从范围var shRm=ss.getSheetByName(“房间”).getDataRange().getValues()获取数据();//工作表名称应为ProjectSetUp并从某个范围获取数据
我尝试过类似的操作,但出现了错误?不确定是否对JSON.Stringify元素进行了哈希运算?
函数doGet(e){if(e.parameter.func=“static”){var app=SpreadsheetApp;var ss=app.getActiveSpreadsheet();var-activeSheet=ss.getSheetByName(ProjectSetUp)//这是一个表名,它将保存我所有的查找数据。var-rgBldg=activeSheet.getRange(“C2:C59”).getValues();var-rgFlr=activeSheet.getRange(“E2:D125”).getValues();返回ContentService.createTextOutput(JSON.stringify({“C2:C59”):rgBldg,“D2:D59”:rgFlr,“E2:D125”:rgRm}).setMimeType(ContentService.MimeType.JSON);}
Hi@Garth!我阅读了您的问题和您的评论。根据您上一次的通信,您是否可以检查变量
ProjectSetUp
是否已声明?如果这没有帮助,请共享代码中返回的错误,以便我能进一步帮助您。
function doGet(e) {

  if ( e.parameter.func == "static" ) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sh = ss.getSheetByName("ProjectSetUp");
    var rgProj = sh.getRange("A3:A3").getValues();