获取电子表格最后一行作为数组以使用字段数据

时间:2016-04-08 18:45:47

标签: google-apps-script google-sheets

我想让最后一行电子表格使用这些字段将数据添加到文档然后发送和发送电子邮件(我可以做)等等。我猜我需要和数组但我只是可以'看怎么样!这就是我所拥有的:

   // initiate select2
 $('.select2').select2(); 
 // delegate a click event on the input box
 $('.select2-input').on('click',function()
 {
   // remove select2-disabled class from all li under the dropdown
   $('.select2-drop .select2-results li').removeClass('select2-disabled');
    // add select2-result-selectable class to all li which are missing the respective class
   $('.select2-drop .select2-results li').each(function()
   {
     if(!$(this).hasClass('select2-result-selectable'))
       $(this).addClass('select2-result-selectable');
   });   
 });

   // had to include the following code as a hack since the click event required double click on 'select2-input' to invoke the event
 $('.select2-container-multi').on('mouseover',function()
 {
   $('.select2-input').click();
 });

所以我可以将数据添加到文档中:

function createNda() {

  // Get the last row
  var lastRowSelect = sheet.getLastRow();

  return lastRowSelect;

  // Get the Range
  var dataRange = sheet.getRange(lastRowSelect, 1, 1, 8);

  // Get the values of the last row
  var data = dataRange.getValues();

  // Present the data of the row

  var ndaData = data;

  // I want to be able to grab the fields like this:

  var Name = ndaData[2];
  var Title = ndaData[3];
  var Email = ndaData[4];
  var Company = ndaData[5];
  var Address = ndaData[6];

我只是没到那儿。

任何帮助都非常感激。

1 个答案:

答案 0 :(得分:2)

getValues()方法获取二维数组。因此,要获取内部数组值,您需要两个索引。或者首先获取内部数组,即行,然后使用行数来获取单元格值。

var thisRow = ndaData[0];

var Name = thisRow[2];
var Title = thisRow[3];
var Email = thisRow[4];
var Company = thisRow[5];
var Address = thisRow[6];