B
B
bebebekov2016-07-22 10:14:09
Data transfer
bebebekov, 2016-07-22 10:14:09

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

2 answer(s)
O
oleg_krechetov, 2016-07-22
@oleg_krechetov

https://developers.google.com/apps-script/referenc...

Z
zamkevich, 2017-05-18
@zamkevich

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()); // получаем массив
?>

At the output, you get a multidimensional array, then the standard methods for working with arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question