12345678910111213141516171819202122232425262728293031323334353637383940 |
- #!/usr/bin/python3
- import sys
- import codecs
- import traceback
- import requests
- import re
- import pandas as pd
- import random
- import urllib
- import json
- import gspread
- import datetime
- from gspread_pandas import Spread, Client
- from oauth2client.service_account import ServiceAccountCredentials
- import os
- df = pd.DataFrame(columns=('F1','F2'))
- df.loc[0]=['中文','測試']
- df.loc[1]=['English','Test']
- scope = ['https://spreadsheets.google.com/feeds',
- 'https://www.googleapis.com/auth/drive']
- credentials = ServiceAccountCredentials.from_json_keyfile_name('c:\\keys\\service\\gspread.json', scope)
- gc = gspread.authorize(credentials)
- #lst=gc.list_spreadsheet_files()
- #print(lst)
- #for l in lst:
- # if l['name']=='S1':
- # l.df_to_sheet(df, index=False, sheet='test_spreadsheet', start='A1', replace=False)
- #sys.exit()
- #wks = gc.open("S1").sheet1
- #print(wks)
- spread = Spread('S1',creds=credentials)
- #spread = Spread(wks)
- #spread=gc.open('S1')
- spread.df_to_sheet(df, index=False, sheet='test_spreadsheet', start='A1', replace=False)
|