Google Spreadsheets获取单元格评论/备注

时间:2013-05-02 22:31:15

标签: zend-framework google-apps-script google-sheets gdata google-spreadsheet-api

我正在学习如何使用gdata api和zend框架。

我基本上得到了一个我想要数据的电子表格。

我已经设法将它变成一个数组,我很高兴使用以下代码(很可能是膨胀)

<?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)

}

我想知道我应该如何解决这个问题呢?

由于

1 个答案:

答案 0 :(得分:0)

使用google-apps-script:创建一个网络应用,并通过谷歌应用脚​​本将值提取到您的代码中。 ---我怀疑这是唯一的选择。我希望被证明是错的。

据我所知,gdata样式api不支持获取注释,字体,颜色等。但是您可以通过将表格作为HTML来获取样式数据。有点乱,但工作正常。