Created
June 30, 2019 15:46
-
-
Save DataSolveProblems/0668bafab7855af3637dad85a6756f58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client as win32 | |
from Google import Create_Service | |
CLIENT_SECRET_FILE = 'client_secret.json' | |
API_SERVICE_NAME = 'sheets' | |
API_VERSION = 'v4' | |
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'] | |
gsheet_id = '<Google Sheets Id>' | |
gsheet_name = 'sheet1' | |
service = Create_Service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES) | |
gs = service.spreadsheets() | |
rows = gs.values().get( | |
spreadsheetId=gsheet_id, | |
range=gsheet_name, | |
).execute().get('values') | |
xlApp = win32.Dispatch('Excel.Application') | |
wb = xlApp.Workbooks('YourExcelFile.xlsx') | |
wsData = wb.Worksheets("Data") | |
wsData.Cells.ClearContents() | |
rowNumber = 1 | |
colCount = len(rows[7]) | |
for row in rows: | |
wsData.Range(wsData.cells(rowNumber, 1), wsData.cells(rowNumber, colCount)).value = row | |
rowNumber += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment