Answer the question
In order to leave comments, you need to log in
Importing data from a google spreadsheet cell to a website?
There is a Google table, you need to get the values of certain cells from it to build a graph on the site.
Is it possible to somehow implement this through php or api? I did not find a ready solution.
Answer the question
In order to leave comments, you need to log in
Everything is even simpler: https://developers.google.com/sheets/api/quickstart/php
Actually, everything is described in great detail.
Here is a mini example:
<?php
require 'vendor/autoload.php';
$service_account_file = 'vendor/key.json'; // путь к файлу ключа
$spreadsheet_id = ''; // id таблицы копируем из адресной строки браузера
$range = 'A:F'; // задаём диапазон ячеек (можно указать лист)
$optparams = []; // создали массив настроек, наполняем его данными:
$optparams['majorDimension'] = 'COLUMNS'; // тип вывода: колонки
$optparams['valueRenderOption'] = 'UNFORMATTED_VALUE'; // выводим неформатированные данные
$optparams['dateTimeRenderOption'] = 'FORMATTED_STRING'; // за исключением даты
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $service_account_file);
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Sheets::SPREADSHEETS_READONLY);
$service = new Google_Service_Sheets($client);
$result = $service->spreadsheets_values->get($spreadsheet_id, $range, $optparams);
$result = ($result->getValues()); // получаем массив
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question