How to convert Excel File-Format to G-Sheet by Drive API upload?


I can upload and convert CSV files by Drive API without any problem, but when sending XLS (rendered with PEAR XLS-Writer) or XLSX (rendered with PHPExcel) the Drive API complains:

"Error calling POST (500) Internal Error"

MIME type "application/" apparently works better than "application/vnd-excel"

When I write out XLSX with content-type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" it's quite the same ... it gets stuck when loading the preview, when convert=true.

When creating files with MS Excel and uploading them manually it works fine.

I can insert/update, download/open the files (all fine) - but I want to convert them.

With all the tests performed I guess the problem is related to the created file-format - or MIME type.

Any hints why the conversion might fail...

"Did ever someone managed to convert rendered XLS/XLSX?"

The question basically is: What is the expected file-format + MIME-type in order to convert to gSheet?

I'd accept any answer for the bounty, which provides a way to convert a multi-dimensional array to gSheet with several pages, in case it's not (yet) possible via the Drive API (for sure that would be the preferred way).

This is a Google Drive API question - there's just no individual tag for this available.

By : syslogic


You can upload your Excel documents onto Google Drive using the app or the Google Drive's SDK but I don't think Google provide any sort of way to convert the files yet.

Might be worth suggesting file conversion to Google's Team? I've never seen a need for it personally as Excel works just fine.

On the last part re alternative approaches, you could simply use the Spreadsheet API to write directly into the spreadsheet This may give you a beneficial side-effect of incremental updates.


By : pinoyyid

Most fast-forward was to render array to Excel 2007 and just install Google Drive App on the Desktops for accessing the data. Spreadsheets API can't create documents, need to do that with Docs API; Currently the API wrapper for PHP not supports both of these endpoints - like this I can revision the files as well. Timely effort: 1h.

Update: When I render XLSX with Excel2007 the conversion fails. When I open the very same file with MS-Excel and "Save As" - I can convert it even over the Drive API.

I noticed some things when unzipping the files and compared:

a) MS-Excel uses values '0/1' instead of 'false/true'

b) Directory 'xl/worksheets/_rels' got removed (maybe useless?).

c) The line-endings of the XML´s were converted from UNIX to DOS.

d) MS-Excel added all the empty cells to the XML - which PHPExcel didn't write out.

e) the relation IDs appear to be shifted ... there some 3 calculation in code??

The problem is, that the generated file-format is not matching the Drive API's XML-parser.

I'm still not exactly sure what is wrong with the generated file-format, but patching the rendered XLSX file with XML files natively created by MS-Excel makes it work:

/* how-to patch the generated XLSX: */

$zip = new ZipArchive();
By : syslogic

This video can help you solving your question :)
By: admin