PC6下载站

分类分类

使用PHP集成Google Spreadsheets 数据

关注+2011-01-24作者:佚名

2 页 添加一个新的工作表


清单 2. 添加一个新的工作表

<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Creating worksheets</title>
    <style>
    body {
      font-family: Verdana;
    }
    </style>   
  </head>
  <body>
    <?php
    // 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);

      // get spreadsheet entry
      $ssEntry = $service->getSpreadsheetEntry(
        'https://spreadsheets.google.com/feeds/spreadsheets/ssid');

      // get worksheet feed for this spreadsheet
      $wsFeed = $service->getWorksheetFeed($ssEntry);

      // create new entry
      $wsEntry = new Zend_Gdata_Spreadsheets_WorksheetEntry();
      $title = new Zend_Gdata_App_Extension_Title('Jan 2011');
      $wsEntry->setTitle($title);
      $row = new Zend_Gdata_Spreadsheets_Extension_RowCount('10');
      $wsEntry->setRowCount($row);
      $col = new Zend_Gdata_Spreadsheets_Extension_ColCount('10');
      $wsEntry->setColumnCount($col);

      // insert entry
      $entryResult = $service->insertEntry($wsEntry,
        $wsFeed->getLink('self')->getHref());
      echo 'The ID of the new worksheet entry is: ' . $entryResult->id;

    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }
    ?>

  </body>
<html>

清单 2 为工作表标题、行计数和列计数创建了 Zend_Gdata_Spreadsheets_Extension 对象,然后将这些对象附着到基础的 Zend_Gdata_Spreadsheets_WorksheetEntry 对象。这种方式简化了理解,同时也使实现更简单。如前所述,最终的条目对象通过 insertEntry() 方法传递给工作表提要 URL。

本文导航
展开全部

相关文章

更多+相同厂商

热门推荐

  • 最新排行
  • 最热排行
  • 评分最高
排行榜

    点击查看更多

      点击查看更多

        点击查看更多

        说两句网友评论

          我要评论...
          取消