Google Sheets API (v4) and C# – Updating Cells

Writing an application in C# and interacting with the Google Sheets API?

We’ve found information on that can be an unfortunately hit or miss kind of situation out there – so we thought we’d share a little bit of what we’ve found to work quite well. In our example we’re going to assume you just want to update a particular cell, on a Google Sheet you’ve created.

Google actually does a really nice job of giving us a .NET Quickstart Guide but in some cases you want to do a little more – and if you’re new to C# or .NET development you might be scratching your head going “okay, where do I go from here?”

Well, with this example below, you can see pretty clearly how to go about creating something that will update a cell on a Google Sheet.

Assuming you’ve successfully completed that .NET quickstart – consider this code above a nice example of how to update a cell on a spreadsheet.

The key parts you will want to pay attention to is this section here:

As you can see you need to update the variable spreadsheetId2 to match your Google spreadsheets ID.

You will need to update the variable range2 to reflect the cell range you’re trying to update.

You will need to update the variable oblist to contain the values you want updated on the spreadsheet as well.

Now if you want to paste the values exactly as they are into the spreadsheet, no problem. The line that controls how that works is this one:

There are essentially two variations of this:

.RAW means the values the user has entered will not be parsed and will be stored as-is. So if your value is “=SUM(A1:A3)”, it will be displayed exactly like that – it will not convert it to a formula.

.USER_ENTERED means the values will be parsed as if the user typed them into the UI. Numbers will stay as numbers, but strings may be converted to numbers, dates, etc. following the same rules that are applied when entering text into a cell via the Google Sheets UI. If you have forumula’s and stuff that you want converted – this would be the option for you.

This kind of gives you a rough ‘bare bones’ example of how you can interact with Google Sheets API v4 within a C# environment – specifically with regards to adding/changing cells on a particular spreadsheet.

If you have other cool snippets you’d like to share – show us in the comments!

Posted on: December 15, 2016

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">