0
我在學習如何使用gdata api和zend框架時感到討厭。Google電子表格獲取單元格評論/筆記
我基本上有一個電子表格,我想要的數據。
我設法得到它到一個數組中,我很高興與使用下面的代碼(最有可能在臃腫)
<?php
/* Load the Zend Gdata classes. */
function number_ending($number){
$suff = array("","st","nd","rd","th");
$index = intval($number);
if($index > 4){
$index = 4;
}elseif($index < 1){
$index = 0;
}
return ($number . $suff[$index]);
}
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_Gbase');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$username = "XXXXXXXXXXXXXXX";
$password = "XXXXXXXXX";
$key = "XXXXXXXXXXXX";
//---------------------------------------------------------------------------------
// Init Zend Gdata service
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service);
$spreadSheetService = new Zend_Gdata_Spreadsheets($client);
//--------------------------------------------------------------------------------
// Example 1: Get cell data
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($key);
$feed = $spreadSheetService->getWorksheetFeed($query);
$entries = $feed->entries[0]->getContentsAsRows();
var_dump($entries);
exit;
//sort the headings out
$headingRow = array_slice($entries[0], 1, 6);
$headings = array();
reset($headingRow);
$month = key($headingRow);
foreach ($headingRow as $key => $value) {
$headings[] = number_ending($value);
}
//sort the content
unset($entries[0]);
$people = array();
foreach($entries as $k => $person){
$person = array_slice($person, 0, 6);
$formatted = array();
foreach ($person as $key => $value) {
$formatted[] = $value;
}
$people[$formatted[0]] = $formatted;
array_shift($people[$formatted[0]]);
}
foreach ($people as $pkey => $person) {
foreach ($person as $key => $date) {
$people[$pkey][$headings[$key]] = $date;
unset($people[$pkey][$key]);
}
}
不過我正在找回的數據不包含任何分配給該單元的註釋/註釋。
所有我被退回是
array (size=10)
0 =>
array (size=85)
'_cokwr' => string 'Column A' (length=11)
'may' => string '29' (length=2)
'_e1qt2' => string '30' (length=2)
'_e35dj' => string '1' (length=1)
'_e4jxw' => string '2' (length=1)
'_e5yid' => string '3' (length=1)
'_faot2' => string '4' (length=1)
'may_2' => string '6' (length=1)
'_yhrze' => string '7' (length=1)
'_yj6jv' => string '8' (length=1)
'_ykl48' => string '9' (length=1)
'_ylzop' => string '10' (length=2)
'_yc5pq' => string '11' (length=2)
'may_3' => string '13' (length=2)
'_ygdf1' => string '14' (length=2)
'_yt0iq' => string '15' (length=2)
'_yuf37' => string '16' (length=2)
'_yvtnk' => string '17' (length=2)
'_yx881' => string '18' (length=2)
'may_4' => string '20' (length=2)
'_yq7dw' => string '21' (length=2)
'_yrlyd' => string '22' (length=2)
'_u4gbe' => string '23' (length=2)
'_u5uvv' => string '24' (length=2)
'_u79g8' => string '25' (length=2)
'may_5' => string '27' (length=2)
'_u08m7' => string '28' (length=2)
'_u1n6k' => string '29' (length=2)
'_u31r1' => string '30' (length=2)
'_ufouq' => string '31' (length=2)
'_uh3f7' => string '1' (length=1)
'june' => string '3' (length=1)
'_ua2l2' => string '4' (length=1)
'_ubh5j' => string '5' (length=1)
'_ucvpw' => string '6' (length=1)
'_ueaad' => string '7' (length=1)
'_uqxe2' => string '8' (length=1)
'june_2' => string '10' (length=2)
'_uv53d' => string '11' (length=2)
'_ulb4e' => string '12' (length=2)
'_umpov' => string '13' (length=2)
'_uo498' => string '14' (length=2)
'_upitp' => string '15' (length=2)
'june_3' => string '17' (length=2)
'_v4z28' => string '18' (length=2)
'_v6dmp' => string '19' (length=2)
'_uwjnq' => string '20' (length=2)
'_uxy87' => string '21' (length=2)
'_uzcsk' => string '22' (length=2)
'june_4' => string '24' (length=2)
'_vet2z' => string '25' (length=2)
'_vg7nc' => string '26' (length=2)
'_vhm7t' => string '27' (length=2)
'_v7s8u' => string '28' (length=2)
'_v96tb' => string '29' (length=2)
'july' => string '1' (length=1)
'_von1u' => string '2' (length=1)
'_vq1mb' => string '3' (length=1)
'_vrg6o' => string '4' (length=1)
'_vsur5' => string '5' (length=1)
'_vj0s6' => string '6' (length=1)
'july_2' => string '8' (length=1)
'_vn8hh' => string '9' (length=1)
'_vzvl6' => string '10' (length=2)
'_w1a5n' => string '11' (length=2)
'_w2oq0' => string '12' (length=2)
'_w43ah' => string '13' (length=2)
'july_3' => string '15' (length=2)
'_vx2gc' => string '16' (length=2)
'_vyh0t' => string '17' (length=2)
'_wb44i' => string '18' (length=2)
'_wcioz' => string '19' (length=2)
'_wdx9c' => string '20' (length=2)
'july_4' => string '22' (length=2)
'_w6wfb' => string '23' (length=2)
'_w8azo' => string '24' (length=2)
'_w9pk5' => string '25' (length=2)
'_11m5ay' => string '26' (length=2)
'_11njvf' => string '27' (length=2)
'julaugust' => string '29' (length=2)
'_11gj1a' => string '30' (length=2)
'_11hxlr' => string '31' (length=2)
'_11jc64' => string '1' (length=1)
'_11kqql' => string '2' (length=1)
'_11xdua' => string '3' (length=1)
}
我不知道我應該如何去有關把它弄出來呢?
感謝
那麼這將學習另一個框架?我有足夠的時間搞這個工作大聲笑。 – Owen 2013-05-03 08:01:34
它比gdata調用簡單得多,沒有oauth2等乾淨的API。也許4-8小時瞭解網絡應用程序的東西。但剩下的只是一個簡單的調用來獲取數據,然後傳遞它。 – eddyparkinson 2013-05-06 02:12:42