使用PHP写入Google Docs电子表格

Abb*_*idi 8 php zend-framework google-sheets google-spreadsheet-api

无论如何,除了Zend库之外,我还能使用PHP将数据写入Google Docs电子表格吗?我已经尝试过Zend库,虽然它很有用,但我希望能够指定要写入的特定行和列,而不是写入指定列的最后一行.从我所看到的,Zend库不具备此功能.

任何链接或代码将不胜感激!

May*_*iya 6

我希望这个对任何人都有用..

// 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());
}
Run Code Online (Sandbox Code Playgroud)


Lia*_*iam 3

Zend 库应该能够编辑电子表格中给定单元格的内容。请参阅此处的文档:http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_php.html#updateCell

“updateCell”方法允许您传入行和列作为目标,并将内容设置为新值。你有机会尝试这个方法吗?