除了Zend库之外,我还能使用PHP将数据写入Google Docs电子表格吗?我已经尝试过Zend库,虽然它很有用,但我希望能够指定要写入的特定行和列,而不是写入指定列的最后一行。从我所看到的,Zend库不具备此功能。
非常感谢任何链接或代码!
答案 0 :(得分: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());
}
答案 1 :(得分:3)
Zend库应该能够编辑电子表格中给定单元格的内容。请参阅此处的文档:http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_php.html#updateCell
'updateCell'方法允许您将行和列作为目标传入,并将内容设置为新值。你有机会尝试这种方法吗?