【问题标题】:Writing to Google Docs Spreadsheet using PHP使用 PHP 写入 Google Docs 电子表格
【发布时间】:2011-09-12 15:49:50
【问题描述】:

除了 Zend 库之外,我是否可以使用 PHP 将数据写入 Google Docs 电子表格?我已经尝试过 Zend 库,虽然它很有帮助,但我希望能够指定要写入的特定行和列,而不是写入指定列的最后一行。据我所见,Zend 库无法做到这一点。

任何链接或代码将不胜感激!

【问题讨论】:

    标签: php zend-framework google-sheets google-spreadsheet-api


    【解决方案1】:

    我希望这对任何人都有用..

    // 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);
    
      // set target spreadsheet and worksheet
      $ssKey = 'ssid';
      $wsKey = 'wsid';
    
      // update cell at row 6, column 5
      $entry = $service->updateCell('6', '5', 'Hello, world', $ssKey, $wsKey);
      echo 'Updated cell ' . $entry->getTitle()->getText() . '';
    
      // clear cell at row 1, column 1
      $entry = $service->updateCell('1', '1', '', $ssKey, $wsKey);
      echo 'Cleared cell ' . $entry->getTitle()->getText();
    
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }
    

    【讨论】:

    【解决方案2】:

    Zend 库应该能够编辑电子表格中给定单元格的内容。在此处查看文档:http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_php.html#updateCell

    “updateCell”方法允许您传入行和列作为目标,并将内容设置为新值。你有没有机会尝试这种方法?

    【讨论】:

    • 谢谢!完美运行!由于可怕的文档,它需要一段时间才能让它工作,但它得到了回报。 :)
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多