在Google Apps Script中返回“范围”而不是实际字符串

Returning 'Range' instead of actual string in Google Apps Script

本文关键字:字符串 范围 Apps Google Script 返回      更新时间:2023-09-26

我使用以下函数在Google表格中返回串联字符串。在这种情况下,B4等于"心脏病学",B1等于"82-01"。

预期结果是dimension2=~cardiology;ga:eventCategory=~MS82-01

但是,我得到了这个结果,dimension2=~Range;ga:eventCategory=~MSRange.

为什么函数返回"范围"而不是实际字符串?

function highLevelData() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // get the spreadsheet object
  SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]); // set the first sheet as active
  var sheet = spreadsheet.getActiveSheet(); // get the active sheet
  var reportConfig = spreadsheet.getSheets()[0]; // set report configuration sheet
  var targetSpecialty = sheet.getRange("B4"); // get target specialty
  var specialtyDimension = "dimension2=~"; // set the sytanx string for the specialty dimension
  var targetCase = sheet.getRange("B1"); // get case
  var eventCategoryDimension = ";ga:eventCategory=~MS"; // set the syntax string for the event category dimension
  var filterOutput = specialtyDimension + targetSpecialty + eventCategoryDimension + targetCase; // concatenate full filter string
  var filterCell = reportConfig.getRange("B11"); // set the filter cell
  filterCell.setValue(filterOutput); // output filter string to filter cell
}

"getRange()" 函数返回一个 Range 对象,该对象表示工作表中的单元格。

若要获取单元格的内容,请在 Range 对象上调用".getValue()"。

var targetSpecialty = sheet.getRange("B4").getValue();

请参阅:https://developers.google.com/apps-script/reference/spreadsheet/range