This topic is locked

Make Google Drive Excel Document Presentable with PHPrunner

8/10/2024 4:34:49 AM
PHPRunner General questions
J
Jan author

Hello everybody,

With a Google rest-api connection, a list can be retrieved from Google drive that can be displayed with phprunner. A working example can be found here.

https://xlinesoft.com/blog/2021/11/02/working-with-google-drive-rest-api/

Is it also possible to display the data of an Excel document that is in Google drive with phprunner?
Are there any examples of this if possible?Thanks for any information.

M
MikeT 8/10/2024

Google has an API for sheets with lots f examples: https://developers.google.com/sheets/api/guides/concepts

C
cristi 8/10/2024

You can look at the example here
It's for locally hosted files but if you have the files hosted on google drive finding the link is easy.
Be aware that there is a 25 MB file size limit for previews.

Another way would be to use an open source library like phpspreedsheet that Fernando made a lot of tutorials on how to use it.
I saw in their documentation that they have an html writer:

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet); //create the writer
$writer->save('previewexcel/'.$filename.'.html'); //save the html file to a temp folder on your server - let's call it previewexcel - or google drive with google drive api - read the docs for google drive api

echo '<iframe src="previewexcel/'.$filename.'.html"></iframe>'; //this is how the iframe code looks like for a file hosted on your server

You can then display the generated html with an iframe inside a popup or use sweetalert 2 that can display html content

This way you have your own solution - but you still need the google cloud api to get the files.

Be aware that: "HTML limitations Please note that HTML file format has some limits regarding to styling cells, number formatting, ... Declared charsets compatible with ASCII in range 00-7F, and UTF-8/16 with BOM are supported" - so if your excel files are formatted the preview will look kind of "funny"...