Monday 4 May 2020

Google Sheet API | Part 3 | Delete Records From Spreadsheet | Remove Row...



Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward

code :-

$requests = [
  new Google_Service_Sheets_Request([
      'deleteDimension' => [
          'range' => [
              'sheetId' => '0',
              'dimension' => 'ROWS',
              'startIndex' => 8,
              'endIndex' => 9
          ]
      ]
  ])
];

$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
    'requests' => $requests
]);

$response = $service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdateRequest);
print_r($response);



------------------------------------------------

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------

Google Sheet API | Part 1 | Connect And Display Sheet Data Using PHP | Latest:-
https://youtu.be/CI0xL93Xtpg

Google Update New Configuration :-
https://youtu.be/5COjnEc4d9E

DELETING ROW IMP Link #1:-
https://developers.google.com/sheets/api/samples/rowcolumn#delete_rows_or_columns

DELETING ROW IMP Link #2:-
https://developers.google.com/sheets/api/guides/batchupdate#example

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys.
This is the video of Deleting Rows in Google Sheet using API.
First, if you don’t know how to connect google sheet with PHP, then watch both videos.
Links of those tutorials are given in description.
Now, as you can see, the current code I have is to display data from google sheet on browser.
Also, I provided two links which are important for deleting rows.
First link is to understand the array structure for deleting.
Second link is a PHP code that we have to implement.
Now In a code, make sure that the scope is SPREADSHEETS and not SPREADSHEET_READONLY
Here, comment the code which fetches the data.
Copy the code from top up to response variable.
Paste it just below spreadsheetID variable.
Now, we actually need one GOOGLE SERVICE SHEETS REQUEST. So remove the second but be careful not to mess the structure.
We also don’t need FIELDS sub-array.
Open the array structure link.
So according to this, the first parent should be “requests” which is already given in code.
So we don’t need to change it.
The second parent is “DELETE DIMENSION”. Paste it.
Third is “RANGE”.
Now RNAGE has 4 key value pairs, so paste them one by one.
Now, the first key which is sheetID is not same as spreadsheetID.
But rather it is sub-sheet.
And it is denoted as GID which you can find in URL.
In my case, the GID is 0.
Now we are deleting rows, so paste ROWS.
Now in spreadsheet, there are numbers which are actual index that we are going to use.
Make sure not to use any quotes, just type numbers.
Also a side note is, startIndex 8 means it does not delete the 8th row, deleting will start
from 9th row up to 10th row.

So if we refresh and check sheet, you see that data from row 9 and 10 are deleted and the
rest were moved upward by 2 positions.
If you want to delete only 1 row that is 9th row, then type 9 at END-INDEX and type 8 at
START-INDEX.

Now the 9th row is deleted.
You can also copy the whole code from blog link which is given in the description.

Don’t forget to like, share and subscribe.
Thanks for watching. 



No comments:

Post a Comment