My previous Sheets API post demonstrated how to add rows to Google Sheets with PHP. Â Some readers were interested in editing or deleting rows.
Google has a very informative reference here that describes the list-based feed for manipulatingÂ sheets. Â All of my scripts have been using this method, which requires the sheet to have a single header row (I’d been lucky to use that format without knowing the requirement). Â I use the example HTTP code from Google’s reference pages to give me guidance for my PHP.
I’ve added a file to the gist demonstrating how to edit a row. Â Here’s what you need to know:
- When you get the sheet list feed (Section 3 of the first file in the gist), you need to add a header (“GData-Version” => “3.0”) to the GET request so that the Etag is returned for each line.
- Once you have a list of entries and find the one that you want to edit, you need to grab its Etag, Id, and the edit URL (see lines 1, 2, and 9 in the image above, and click on the image to see the whole entry).
- Now you just need to issue a PUT request to the edit URL and include the XML with the Etag, Id, and updated sheet data.
Hope this helps a few people!