Writing to Google Docs Spreadsheet using PHP

前端 未结 2 817
悲&欢浪女
悲&欢浪女 2021-02-06 05:20

Is there anyway I could write data to a Google Docs Spreadsheet using PHP, besides the Zend library? I have tried the Zend library, and while it is helpful, I want to be able to

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 06:05

    I Hope this one useful for anyone..

    // 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());
    }
    

提交回复
热议问题