Reputation: 2097
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.
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 ?
Upvotes: 4
Views: 1270
Reputation: 15328
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
Upvotes: 0
Reputation: 15328
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();
Upvotes: 1