How to download multiple worksheets using Smartsheet API?

450 Views Asked by At

I want to script the download of 8 sheets using the module smartsheet-python-sdk.

Later I want to automate the download scheduled at a specific time once a week with Windows Task Scheduler.

But I have trouble with the Python script downloading the sheets via API.

This is what I have in a .py file.

import os, smartsheet

token=os.environ['SMARTSHEET_ACCESS_TOKEN']

smartsheet_client = smartsheet.Smartsheet(token)

smartsheet_client.errors_as_exceptions(True)

smartsheet_client.Reports.get_report_as_excel(
  8729488427892475,
  'C:/Desktop',
  'MyFileName.xlsx'
)
1

There are 1 best solutions below

3
On BEST ANSWER

I notice a couple of issues with the code you've posted.

First, smartsheet_client.Reports.get_report_as_excel should be smartsheet_client.Sheets.get_sheet_as_excel if you're wanting to retrieve a sheet (not a report).

Next, try specifying the full path for where Desktop actually lives on the file system. i.e., instead of just using the alias C:\Desktop -- specify the actual file system path, for example: c:/users/USERNAME/desktop (on a Windows machine) where USERNAME is the name of the currently logged in user. You can also derive the logged-in user dynamically, see How to make Python get the username in windows and then implement it in a script.

The following code successfully downloads the specified sheet to my Desktop, with the filename MyFileName.xlsx. (I'm logged in as kbrandl so the path to my Desktop is specified as: c:/users/kbrandl/desktop.)

sheetId = 3932034054809476

smartsheet_client.Sheets.get_sheet_as_excel(
    sheetId,
    'c:/users/kbrandl/desktop',
    'MyFileName.xlsx'
)