duanhan9334 2011-02-19 16:09
浏览 32

通过php从Google Spreadsheet打印随机行

I would like to create a PHP script that fetches a few rows from a Google Spreadsheets and display it in html.

$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);
$gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$feed = $gdClient->getSpreadsheetFeed('https://spreadsheets.google.com/ccc?key=MY_DOC_KEY');
$currKey = explode('/', $feed->entries[0]->id->text);
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($this->currKey);
$query->setWorksheetId($this->currWkshtId);
$query->setMinCol(1);
$query->setMaxCol(7);
$query->setMinRow(2);
$feed = $gdClient->getCellFeed($query);

However that throws a really ugly error message. What am i doing wrong?

Fatal error: Uncaught exception 'Zend_Gdata_App_Exception' with message 'DOMDocument cannot parse XML: DOMDocument::loadXML() Extra content at the end of the document in Entity, line: 23'

  • 写回答

2条回答 默认 最新

  • doulian5857 2011-02-20 22:50
    关注

    Short answer:

    Why do you want to list the spreadsheets if you already know which spreadsheet you want to read from?

    Long answer:

    I am new to both Zend and Gdata, but tried to run your code and got the same exception. But after reading the docs (http://framework.zend.com/manual/en/zend.gdata.spreadsheets.html) I've tried replacing:

    $feed = $gdClient->getSpreadsheetFeed('https://spreadsheets.google.com/ccc?key=MY_DOC_KEY');
    

    with:

    $feed = $gdClient->getSpreadsheetFeed();
    

    and after adding the obvious:

    foreach($feed as $cellEntry) {
      $row = $cellEntry->cell->getRow();
      $col = $cellEntry->cell->getColumn();  
      $val = $cellEntry->cell->getText();    
      echo "$row, $col = $val
    ";      
    }        
    

    I got some data.

    Then I understood, these two lines are not needed at all:

    $feed = $gdClient->getSpreadsheetFeed('https://spreadsheets.google.com/ccc?key=MY_DOC_KEY');
    $currKey = explode('/', $feed->entries[0]->id->text);
    

    So getSpreadsheetFeed is useful if you want to list/filter spreadsheets (and then there's no point in suplying the key) and to read the data from the known spreadsheet it's enough to use just the Zend_Gdata_Spreadsheets_CellQuery.

    Now I learned something.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。