SHARE
TWEET

Untitled

a guest Dec 16th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // ...
  3.     public function set($collection="My Friendly Sheet Name",$sheet="",$range="",$values=array()) {
  4.         $result = [];
  5.  
  6.         $keys   = array("collection","sheet","range","values");
  7.         foreach ($keys as $k) {
  8.             $$k = (isset($_GET[$k])) ? $_GET[$k]:$$k;
  9.             if (!$$k) $result = ["success"=>false,"msg"=>"Missing key: $k"];
  10.         }
  11.         if (gettype($values)=="string") {
  12.             $b64    = base64_decode($values);
  13.             if ($b64)   $values = json_decode(unserialize($b64),true);
  14.             else        $values = json_decode($values,true);
  15.         }
  16.         if (!$values) $result = ["success"=>false,"msg"=>"Invalid value array provided"];
  17.  
  18.         if (!$result) {
  19.             $spreadsheetId = $this->collection[$collection];
  20.             $range  = "$sheet!$range";
  21.             $_values = new Google_Service_Sheets_ValueRange();
  22.             $_values->setValues($values);
  23.             $_values->setMajorDimension("ROWS");
  24.             $options = ["valueInputOption" => "RAW"];
  25.             $res = $this->_sheets->spreadsheets_values->update($spreadsheetId,$range,$_values,$options);
  26.  
  27.             if ($res->spreadsheetId) $result = ["success"=>true,"msg"=>sprintf("Updated %d cells",$res->updatedCells)];
  28.         }
  29.  
  30.         echo json_encode($result);
  31.     }
  32. // ...
  33. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top