Demo entry 5625015

mypythoncode

   

Submitted by anonymous on Jul 05, 2016 at 17:48
Language: Python. Code size: 1.1 kB.

def import_rows(service,param_csv_file,param_table_id):
    # the data is inserted into a table in two steps
    try:
	# 1. we need to create an object of the type "MediaFileUpload" with the CSV file and the mime type of "application/octet-stream"
        media = http.MediaFileUpload(param_csv_file,
                                    mimetype='application/octet-stream',
                                    resumable=True)
                                    
        # 2. then the object is provided as a parameter to the "importRows()" function along with the hash code of the table 
        request = service.table().importRows(media_body=media, tableId=param_table_id, startLine=1).execute()
        # parameter startLine=1 is necessary, because of first line, which contains the header names
        
        # 3. on success the result is a JSON string, which confirms the number of provided rows in the field "numRowsReceived"
        return request['numRowsReceived']
        
    except errors.HttpError, e:
        print('Error handling: ',e) 

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).