0
votes

I have excel file it contain one sheet it contain image. I need convert this excel file to google spreadsheet using python.

I can create google spreadsheet using api and add my text data but i can't to add image. This way does not suit me.

But I can to generate excel file contained image. Now I need export excel sheet to google spreadsheet.

How i can do it?

1

1 Answers

0
votes

You can convert an Excel file to a Google Sheets file using the DRIVE API method Files: copy

You just need to know the fileId and specify the option convert=true.

Sample:

service.files().copy(fileId=file_id,convert=true, body={"title": "Chose a title"}).execute()

If your excel file is on your local disc - upload it to a Google Sheets file as following:

file_metadata = {
    'name': 'Desired Name',
    'mimeType': 'application/vnd.google-apps.spreadsheet'
}
media = MediaFileUpload('files/myExcelFile.xls',
                        mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                        resumable=True)
file = drive_service.files().create(body=file_metadata,
                                    media_body=media,
                                    fields='id').execute()
print 'The converted file is on your Google Drive and has the Id: %s' % file.get('id')

More information here and here.