nidup / manipulate-google-sheets-api-in-php

Code examples for the tutorial How to Use Google Sheets API in PHP?
https://www.nidup.io/blog/manipulate-google-sheets-in-php-with-api
MIT License
22 stars 4 forks source link

Get the values and their cell range for each one for updating one row later #1

Open kabeza opened 1 year ago

kabeza commented 1 year ago

Hi Nico Not an issue but a question:

I call $response->get_values(); and all works fine, but I'd like to get the cell range for the values in specific column

Let's say I'd like to modify a row, right? I have a column with people's SSN (social security number) which is a univocal data. I want to modify a person's name/surname for a specific SSN, but I don't know where is that row located in the Spreadsheet... Therefore I must search this SSN value before modifying it and get its location in the SpreadSheet, eg Sheet1!D18

Is there a way to search in the SpreadSheet and get the cell for the specific value searched? Or to get all the values with their corresponding cell range/location ...?

Thanks a lot in advance,

PS: Excellent article/post. Very detailed/useful https://www.nidup.io/blog/manipulate-google-sheets-in-php-with-api

tacman commented 4 months ago

you'd want to read the data and create a hash of the row indexes for each value. If you know the field is unique, like SSN, you can just create the list pointing to a row, then use that data to update.


$ssnToRow = [
   '123' => 'A1',
   '234' => 'A2'
];

then update the row ->update($ssnToRow['234'], [new values])