Answer the question
In order to leave comments, you need to log in
How to create a table via Google Docs API?
require_once __DIR__ . '/vendor/autoload.php';
function initializeSheets(){
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
$client = new Google_Client();
$client->setApplicationName("Google Sheets API PHP Quickstart");
$client->setAuthConfig($KEY_FILE_LOCATION);
$sheets = $client->setScopes(implode(' ', array(Google_Service_Sheets::SPREADSHEETS_READONLY)));
return $sheets;
}
$sheets = initializeSheets();
$sfsef = new Google_Service_Sheets_GridProperties();
$sfsef->setRowCount(8);
$sfsef->setColumnCount(5);
$sheet111 = new Google_Service_Sheets_SheetProperties();
$sheet111->setSheetType('GRID');
$sheet111->setSheetId(0);
$sheet111->setTitle('название листа');
$sheet111->setGridProperties($sfsef);
$sheet = new Google_Service_Sheets_Sheet();
$sheet->setProperties($sheet111);
$properties = new Google_Service_Sheets_SpreadsheetProperties();
$properties->setTitle('название документа');
$properties->setLocale('ru_RU');
$spreadsheets1 = new Google_Service_Sheets_Spreadsheet();
$spreadsheets1->setProperties($properties);
$spreadsheets1->setSheets($sheet);
$result = $sheets->spreadsheets->create( $spreadsheets1 ) ;
echo '<pre>';
print_r($result);
echo '</pre>';
Google_Service_AnalyticsReporting_GetReportsRequest
, but I can't find a similar function for tables.
Answer the question
In order to leave comments, you need to log in
I leave the working code here, maybe the cat will need it, because I found only one good article, and then on python, no one wants to upload and share, but I'm not greedy)
require_once __DIR__ . '/vendor/autoload.php';
function initializeSheets(){
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
$client = new Google_Client();
$client->setApplicationName("Google Sheets API PHP Quickstart");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/spreadsheets']);
return $client;
}
$sheets = new Google_Service_Sheets(initializeSheets());
//создаем саму таблицу
$sfsef = new Google_Service_Sheets_GridProperties();
$sfsef->setRowCount(8);
$sfsef->setColumnCount(5);
$sheet111 = new Google_Service_Sheets_SheetProperties();
$sheet111->setSheetType('GRID');
$sheet111->setSheetId(0);
$sheet111->setTitle('название листа');
$sheet111->setGridProperties($sfsef);
$sheet = new Google_Service_Sheets_Sheet();
$sheet->setProperties($sheet111);
$properties = new Google_Service_Sheets_SpreadsheetProperties();
$properties->setTitle('название документа');
$properties->setLocale('ru_RU');
$spreadsheets1 = new Google_Service_Sheets_Spreadsheet();
$spreadsheets1->setProperties($properties);
$spreadsheets1->setSheets($sheet);
$result = $sheets->spreadsheets->create( $spreadsheets1 ) ;
//даем доступ для редактирование кому угодно
$drive = new Google_Service_Drive(initializeSheets());
$drive1 = new Google_Service_Drive_Permission();
$drive1->setType('anyone');
$drive1->setRole('writer');
$drive1s = $result['spreadsheetId'];
$resultqqq = $drive->permissions->create( $drive1s, $drive1 ) ;
echo '<pre>';
print_r($result);
echo '</pre>';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question