Skip to content

Instantly share code, notes, and snippets.

@mithunkamat
Created May 18, 2020 07:10
Show Gist options
  • Save mithunkamat/a553a81dc96f331b81c5eaeacb131aab to your computer and use it in GitHub Desktop.
Save mithunkamat/a553a81dc96f331b81c5eaeacb131aab to your computer and use it in GitHub Desktop.
Snippet showing how to set a tab called 'Mapping' as the active sheet with openpyxl.
# first we set the path to Excel file
path = r".\documents\tool_setup.xlsx"
# open the file as a workbook object
wb = openpyxl.load_workbook(path, data_only=True)
# find the index of 'Mapping' sheet
idx = [i for i, name in wb.sheetnames if name == 'Mapping'][0]
# set the mapping sheet as active
wb.active = idx
ws = wb.active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment