Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to an empty cell in Google Spreadsheets

I would like to have some Javascript code running in a web browser write to a Google Spreadsheet in the user's Google account.

The Javascript API is a bit long-winded, involving lots of round trips, but does seem to work. I can successfully log in, create a new spreadsheet, read values from it, update cells, etc. However, I haven't yet figured out how to write to an empty cell. (By empty, I mean that a cell that has had no value written into it yet.)

The issue is: in order to update the value of a cell, I need to know that cell's id. To get the cell's id, I read the cell feed, which shows me the contents (and id) of all non-empty cells. However it won't show me empty cells, therefore I don't know their id, therefore I can't write to them. I've tried making up my own id based on the naming pattern of the other cells, but that doesn't work.

There must be an easy way round this. What is it?

(Context: what I'm actually doing is trying to store user preferences in the user's Google account. The spreadsheet API seems like to be the only one that's feasible to use from a pure Javascript environment. If anyone can suggest any alternatives that's easier to use than Spreadsheets, I'd be grateful.)

like image 227
David Given Avatar asked Aug 27 '10 19:08

David Given


People also ask

How do I mark a blank cell in Google Sheets?

First, select the entire data range. Then in the Ribbon, go to Home > Find & Select > Go To Special. 2. In Go To Special dialog window click on Blanks and when done press OK.


1 Answers

I was about to ask a similar question when I stumbled upon yours and while in the process of compiling my question I found the answer!

http://code.google.com/apis/spreadsheets/data/2.0/reference.html#CellParameters

There is a property called return-empty which is set to false by default hence only returning cells that aren't empty in the feed. Set this to "true" in your cell query and you will be able to update the value of empty cells.

I've testing this using the .NET API .

like image 98
User123342234 Avatar answered Oct 25 '22 18:10

User123342234