gdrive icon indicating copy to clipboard operation
gdrive copied to clipboard

Converting CSV file to Google Spreadsheet through gdrive api not working

Open karunasaxena opened this issue 7 years ago • 6 comments

I have tried following commands to make csv file open as a spreadsheet while I am uploading through gdrive tool but always it is uploading as a google doc or ms-excel. But for either of the case I have to select the option "Open With" -> Google Spreadsheet which is creating one extra file of same name.

sample.csv 1,2,3,4

gdrive upload sample.csv gdrive upload --mime 'text/csv' sample.csv gdrive import sample.csv gdrive upload --mime 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' sample.csv

Can anyone please help me on this?

karunasaxena avatar Jun 04 '17 20:06 karunasaxena

I think the command ought to be:

gdrive import --mime 'text/csv' sample.csv # Edit - sorry, import not upload

Imported [ID] with mime type: 'application/vnd.google-apps.spreadsheet'

However that isn't working for me - I get a text document. I wonder whether it ought to be using application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, which has worked for me using the API directly.

shellac avatar Jun 07 '17 10:06 shellac

Same problem here.

demidovakatya avatar Jun 07 '17 11:06 demidovakatya

For anyone else having issues with this here is (sort of) a work around.

  • Create an empty sheet.
  • Get the ID of the sheet (e.g. list contents of drive, or look at url bar).
  • Update the sheet with your CSV (gdrive update SHEET_ID my.csv).

However it's far from perfect (I'm using a service account, for example).

This python code works, so I suspect gdrive is at fault:

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
import httplib2

scopes = ['https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'etc/credentials.json', scopes)

http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build("drive", "v3", http=http)

file_metadata = {
  'name' : 'Test Sheet',
  'mimeType' : 'application/vnd.google-apps.spreadsheet',
  'parents' : []
}

media = MediaFileUpload('test.csv',
                    mimetype='text/csv',
                    resumable=True)

file = drive_service.files().create(body=file_metadata,
                                media_body=media,
                                fields='id').execute()

shellac avatar Jun 08 '17 14:06 shellac

Thanks. It might be a good temporary solution if it works.

For time being, this methodology can be referred either by using gdrive or by using any other free extension say "Sheetgo"

karunasaxena avatar Jun 08 '17 14:06 karunasaxena

Since this is still open, might as well tell you what has worked for me:

gdrive upload --mime text/csv sample.csv

Hope it helps for the future.

lucasclopesr avatar Feb 07 '20 17:02 lucasclopesr

Is there any way to get this to work for gdrive sync upload? I'm uploading data in bulk - only filetype is csv but there's also an underlying directory structure.

AnselmC avatar Aug 25 '21 13:08 AnselmC