8

Is there anyway I could write data to a Google Docs Spreadsheet using PHP, besides the Zend library? I have tried the Zend library, and while it is helpful, I want to be able to specify a specific row and column to write to, instead of writing to the last row of the specified column. From what I have seen, the Zend library is not capable of this.

Any links or code would be greatly appreciated!

Charles
  • 50,943
  • 13
  • 104
  • 142
Abbas Zaidi
  • 85
  • 1
  • 1
  • 6

2 Answers2

6

I Hope this one useful for anyone..

// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

// set credentials for ClientLogin authentication
$user = "someuser@gmail.com";
$pass = "somepass";

try {
  // connect to API
  $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
  $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  $service = new Zend_Gdata_Spreadsheets($client);

  // set target spreadsheet and worksheet
  $ssKey = 'ssid';
  $wsKey = 'wsid';

  // update cell at row 6, column 5
  $entry = $service->updateCell('6', '5', 'Hello, world', $ssKey, $wsKey);
  echo 'Updated cell ' . $entry->getTitle()->getText() . '';

  // clear cell at row 1, column 1
  $entry = $service->updateCell('1', '1', '', $ssKey, $wsKey);
  echo 'Cleared cell ' . $entry->getTitle()->getText();

} catch (Exception $e) {
  die('ERROR: ' . $e->getMessage());
}
Mayur Kukadiya
  • 994
  • 6
  • 20
  • i got 'ERROR: Expected response code 200, got 400 The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it.' – vignesh.D Oct 08 '14 at 06:48
  • How do I get this Zend library? – Mike Warren Dec 15 '14 at 03:58
  • @MikeWarren You can find the downloads on their website here: http://www.zend.com/company/community/framework/downloads – Andrew Dec 20 '14 at 05:16
  • 1
    not working anymore http://stackoverflow.com/questions/30472059/zend-gdata-and-google-spreadsheet-not-connecting – Michal - wereda-net May 27 '15 at 18:26
3

The Zend library should be able to edit the contents of a given cell within the spreadsheet. See documentation here: http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_php.html#updateCell

The 'updateCell' method allows you to pass in a row and column as your target, and set the contents to the new value. Have you had a chance to try this method?

Liam
  • 1,712
  • 1
  • 17
  • 30
  • Thanks! Works perfectly! It took a while to get it working because of the horrible documentation, but it paid off. :) – Abbas Zaidi Sep 13 '11 at 19:39