'How can I extend bytes csv coverage on my python script
When I input 1 or 10000 csvContents = csv_file.read(10000) it limits the data on csv that transfer to spreadsheet, my goal is to capture all columns and rows, can someone help me what I need to modify with my script to capture entire csv file?.
def extract_csv(csv, sheet_id):
with open(csv, 'r') as csv_file:
csvContents = csv_file.read(1)
body = {
'requests': [{
'pasteData': {
"coordinate": {
"sheetId": sheet_id,
"rowIndex": "0",
"columnIndex": "0",
},
"data": csvContents,
"type": 'PASTE_NORMAL',
"delimiter": ',',
}
}]
}
Thank you in advance!
Solution 1:[1]
You probably want the csv library.
import csv
def extract_csv(csv, sheet_id):
with open('eggs.csv', 'r') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
print(', '.join(row))
Solution 2:[2]
You probably want to use the import_csv.
This method will import the entire content of the CSV file and create a new sheet with the content.
See documentation for details it contains a example.
Warning: read the side note, this method will remove all sheets from your spreadsheet then replace the first sheet with the content of the CSV file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | brunns |
Solution 2 | Lavigne958 |