【发布时间】:2014-06-14 00:31:39
【问题描述】:
我正在尝试通过 PHP/Zend 脚本从 Google 电子表格中获取所有行。这是我正在使用的脚本:
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient('xxxxxxxxx', 'xxxxxxx', $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
// Get spreadsheet key
$spreadsheetsKey = 'xxxxxxxxxxxxx';
$worksheetId = 'xxx';
// Get cell feed
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$query->setWorksheetId($worksheetId);
$cellFeed = $spreadsheetService->getCellFeed($query);
// Build an array of entries:
$ssRows = array();
$ssRow = array();
$titleRow = array();
$tableRow = 1;
foreach($cellFeed as $cellEntry) {
$row = $cellEntry->cell->getRow();
$col = $cellEntry->cell->getColumn();
$val = $cellEntry->cell->getText();
// Add each row as a new array:
if ($row != $tableRow) {
array_push($ssRows, $ssRow);
$ssRow = array();
// Move to the next row / new array
$tableRow = $row;
}
// Build the array of titles:
if ($row == 1) {
$titleRow[$col] = $val;
}
// Build the array of results with the title as the key:
else {
$key = $titleRow[$col];
$ssRow[$key] = $val;
}
}
// Pass the results array:
return array_reverse($ssRows);
这为我构建了一个包含电子表格中大部分详细信息的数组,但是它总是错过最后一个条目 - 任何人都可以看到我做错了什么,或者有没有更好的方法从电子表格中获取所有数据?
该表格由 3 部分组成,基于不同的答案。在填写一个部分时,我想显示一个返回表单的 URL,其中预先填写了第一个表单中的一些详细信息,以便更快地填写表单的第二部分。这一切都很好,只是缺少最后一个条目才是主要问题!
谢谢!
【问题讨论】:
标签: php zend-framework google-sheets gdata