Reputation: 1033
I'm using Go API https://developers.google.com/sheets/api/quickstart/go
I have a sheet looks like this and want to automate some cell filling logic
| B | C |
--+------+------+
1 | b1 | c1 |
--+------+ |
2 | b2 | |
--+------+------+
3 | b3 | |
--+------+------+
While using readRange := "B1:C"
by
resp, _ := s.srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do()
for _, row := range resp.Values {
...
}
I can't tell the difference between C2 and C3. In this case, I would like to fill some values to C3 but not C2. How do I check this via API?
Upvotes: 2
Views: 2491
Reputation: 201653
From your replying, I could understand like above. If my understanding is correct, the method of spreadsheets.values.get cannot retrieve the information of merge cells. In this case, please use the method of spreadsheets.get. The modified script is as follows.
ranges := []string{"B1:C"}
resp, _ := s.srv.Spreadsheets.Get(spreadsheetId).Ranges(ranges...).Do()
for _, sheet := range resp.Sheets {
for _, merge := range sheet.Merges {
fmt.Printf("%#v\n", merge)
}
}
B1:C
means B1:C
of the first tab.When you run above script, you can retrieve the coordinates of the merged cells as the GridRange like below.
{
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 2,
"startColumnIndex": 2,
"endColumnIndex": 3
}
C1:C2
of sheet ID 0
as the a1Notation.
C1:C2
is the merged cell.C1
, the value is displayed. But when the value is put in C2
, the value is not displayed. Please be careful this.Upvotes: 1