Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ...
- public function set($collection="My Friendly Sheet Name",$sheet="",$range="",$values=array()) {
- $result = [];
- $keys = array("collection","sheet","range","values");
- foreach ($keys as $k) {
- $$k = (isset($_GET[$k])) ? $_GET[$k]:$$k;
- if (!$$k) $result = ["success"=>false,"msg"=>"Missing key: $k"];
- }
- if (gettype($values)=="string") {
- $b64 = base64_decode($values);
- if ($b64) $values = json_decode(unserialize($b64),true);
- else $values = json_decode($values,true);
- }
- if (!$values) $result = ["success"=>false,"msg"=>"Invalid value array provided"];
- if (!$result) {
- $spreadsheetId = $this->collection[$collection];
- $range = "$sheet!$range";
- $_values = new Google_Service_Sheets_ValueRange();
- $_values->setValues($values);
- $_values->setMajorDimension("ROWS");
- $options = ["valueInputOption" => "RAW"];
- $res = $this->_sheets->spreadsheets_values->update($spreadsheetId,$range,$_values,$options);
- if ($res->spreadsheetId) $result = ["success"=>true,"msg"=>sprintf("Updated %d cells",$res->updatedCells)];
- }
- echo json_encode($result);
- }
- // ...
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement