Writing to Google Docs Spreadsheet using PHP

感情迁移 提交于 2019-12-03 12:59:58

问题


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!


回答1:


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?




回答2:


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());
}


来源:https://stackoverflow.com/questions/7390557/writing-to-google-docs-spreadsheet-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!