I am trying to get a Google spreadsheet created using a PHP script. Since there seems to be no native PHP API for creating spreadsheets (it can only find Java and .NET), I figured that the easiest way would be to create XLSX and convert it to a Google spreadsheet.
File upload works fine:
$mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
$file = new Google_DriveFile();
$file->setTitle('My Spreadsheet');
$file->setMimeType($mime);
$data = file_get_contents('my_spreadsheet.xlsx');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => $mime,
'convert' => true,
));
However, when it appears in Google Drive, it is a regular Excel file. I have to right-click it on the web interface of Google Drive and select "Open in Google Sheets" before converting it (but the conversion does not contain errors).
How can I force a file conversion?
source
share