manipulate-google-sheets-api-in-php icon indicating copy to clipboard operation
manipulate-google-sheets-api-in-php copied to clipboard

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

Open kabeza opened this issue 2 years ago • 1 comments

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

kabeza avatar Apr 14 '23 13:04 kabeza

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])

tacman avatar May 12 '24 17:05 tacman