4

I am using Google Sheets API to display the data from my Google Spreadsheet in my javascript application. Have developed by refering this documentation. I could able to read the values from my spreadsheet but for some of the columns the cells are merged as below.

enter image description here

I am getting the Json response as

[
[
  "Name",
  "Age"
 ],
[
  "John",
  "25"
 ],
[
  "Doe"
 
 ],
]

My expected output should be

   [
[
  "Name",
  "Age"
 ],
[
  "John",
  "25"
 ],
[
  "Doe",
   "25"
 
 ],
]

Any help ?

Jagadeesh
  • 1,967
  • 8
  • 24
  • 47

2 Answers2

1

To retrieve the value, you have to test if the cell is part of a merged area.

var value = (cell.isPartOfMerge() ? cell.getMergedRanges()[0].getCell(1,1) : cell).getValue();
Mike Steelson
  • 14,650
  • 2
  • 5
  • 20
0

Modify the script as following

    appendPre('Name, Major:');
    var lastData=''
    for (i = 0; i < range.values.length; i++) {
      var row = range.values[i];
      if (row[4]!=''){lastData=row[4]}
      // Print columns A and lastData, which correspond to indices 0 and the last known value in column E that contains merged cells.
      appendPre(row[0] + ', ' + lastData);
    }

so that you will recall the last value if the cell is empty

Mike Steelson
  • 14,650
  • 2
  • 5
  • 20