D
D
direx2016-08-16 17:50:40
Google
direx, 2016-08-16 17:50:40

How to calculate coordinates for google spreadsheets?

Good afternoon. Need help calculating coordinates in Google spreadsheets.
What is:

$spreadsheetId = "индификатор_документа";
        $range = "Книга1!A1:ZZ1";
        $response = $service->spreadsheets_values->get($spreadsheetId, $range);
        $values = $response->getValues();

Using standard api tools, I get an array in response:
array:1 [
  0 => array:97 [
    0 => ""
    1 => "Ссылка на отчет"
    2 => "Итого июнь"
    3 => "01.06.2016"
    4 => "02.06.2016"
    5 => "03.06.2016"
    6 => "04.06.2016"
    7 => "05.06.2016"
    8 => "06.06.2016"
    9 => "07.06.2016"
    10 => "08.06.2016"
    11 => "09.06.2016"
    12 => "10.06.2016"

After I need to calculate the index of the cell that needs to be changed. For example, let it be row number 3, column where date = 06/07/2016 (index = 9)
Well, now I have the exact coordinates of the cell that I need to change. But alas,
$service->spreadsheets_values->update
he asks me to enter the coordinates not 3.9 but 4:I - Where "I" is the column number.
Question:
How can I convert or calculate my coordinates into a format that api accepts?
Solutions :
function getNameFromNumber($num)
    {
        $numeric = $num % 26;
        $letter = chr(65 + $numeric);
        $num2 = intval($num / 26);
        if ($num2 > 0) {
            return getNameFromNumber($num2 - 1) . $letter;
        } else {
            return $letter;
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
direx, 2016-08-16
@ponich

Issue resolved. Thanks

function getNameFromNumber($num)
    {
        $numeric = $num % 26;
        $letter = chr(65 + $numeric);
        $num2 = intval($num / 26);
        if ($num2 > 0) {
            return getNameFromNumber($num2 - 1) . $letter;
        } else {
            return $letter;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question