Answer the question
In order to leave comments, you need to log in
From file to Google Sheets using Python?
I need text from a word document to be inserted into Google Sheets line by line, starting at A3 and down the column.
import gspread
import json
import pyperclip
import config
from oauth2client.client import SignedJwtAssertionCredentials
varss = pyperclip.paste()
with open(config.text, 'a', encoding='utf-8') as f: f.write(str(varss))
scope = ['https://spreadsheets.google.com/feeds']
json_key = json.load(open('creds.json'))
creds = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)
gc = gspread.service_account(filename='creds.json')
sh = gc.open("ADSS")
w = open("texts.txt")
for line in w:
worksheet = sh.worksheet("1ss")
worksheet.update_acell("A3", str(line))
Answer the question
In order to leave comments, you need to log in
This code does what you need.
You need to share the table for the service account, which is registered in the credentials.
Text file, read line by line and immediately write to a table
import gspread
sheet_key = 'id таблицы'
work_sheet_name ='название листа'
gc = gspread.service_account(filename='credentials.json')
sh = gc.open_by_key(sheet_key)
worksheet = sh.worksheet(work_sheet_name)
f = open('texts.txt', 'r', encoding='utf-8')
i = 3
for line in f:
range = 'A'+str( i)
worksheet.update(range, line)
i = i+1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question