1

I want to export the local excel data to google sheets. I got all APIs and requirements. Now, I'm trying to that python script in this link https://blog.coupler.io/python-to-google-sheets/#:~:text=append()-,Python%20script%20to%20export%20Excel%20to%20Google%20Sheets,-Already%20have%20an

def export_excel_to_sheets():
    spreadsheet_id = '1JCEHwIa4ZzwAiKGmAnWGfbjeVCH_tWZF6MkIU0zICwM'
    excel_data_df = pandas.read_excel('sample-excel.xlsx', sheet_name='Sheet1', skiprows = range(1, 62), engine='openpyxl')
    excel_data_df['Date'] = excel_data_df['Date'].astype(str)
    excel_data_df['Unnamed: 0'] = ''
    body = {
        'values': excel_data_df.values.tolist()
    }
    
  
    spreadsheet_service.spreadsheets().values().append(
        spreadsheetId=spreadsheet_id, body=body, valueInputOption='USER_ENTERED', range='Sheet1').execute()
    print('{0} cells appended.'.format(result \
                                       .get('updates') \
                                       .get('updatedCells')))
export_excel_to_sheets()

I have 70 rows of data and I want to export them to Google Sheets. I don't want to "skip" any rows with "skiprows = range(1,62)" so I delete or decrease the value. When I delete this code, the script gets a HTTP400 error.

excel_data_df = pandas.read_excel('example.xlsx', sheet_name='Sheet1', skiprows = range(1, 62), engine='openpyxl')

When I delete "skiprows" code, get a HttpError 400.

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1VIWNRrBF3E9KQo_nT7ZXvT4qQYWymITAFLx2rDEGSPw/values/Sheet1:append?valueInputOption=USER_ENTERED&alt=json returned "Invalid JSON payload received. Unexpected token.
api/v1/users/home", NaN, "{ 'Content-Typ
                    ^">

I want to export all data to Google Sheets without a problem. What is your suggestion to do that? Thank you.

2
  • In order to correctly understand your current issue of Invalid JSON payload received. Unexpected token., can you provide the sample XLSX file? Because, when I tested your showing script, even when skiprows = range(1, 62) is removed using a sample XLSX file, no error occurs. I apologize for this. Commented Nov 11, 2022 at 7:18
  • 1
    I had an empty cell in my excel. I fixed it and now, it works. Thank you for paying attention. Commented Nov 11, 2022 at 8:05

1 Answer 1

0

I think answer below will solve your problem, please give it a try. If it doesn't work let me know. https://github.com/burnash/gspread/issues/680#issuecomment-561936295

Sign up to request clarification or add additional context in comments.

4 Comments

These links should be comments.
I can't comment, I have 48 reputation
Expand your answer so it is not link only then I will give you a vote…
The problem is I have an empty cell in my excel. I add "None" value. This works for me. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.