List Excel File Sheet Names as an Input Parameter for Custom tools in ArcGIS Pro with ArcPy & Pandas

Table of Contents

The Video

Introduction

The Excel to Table Geoprocessing tool takes an Excel file as a parameter and then exposes the sheet names for the that file as a selection list in another parameter. In this blog post we will see how to use pandas and ArcPy in the custom tool Validator to achieve the same functionality if required for a bespoke workflow.

ArcGIS Pro Definition Query Masterclass with ArcPy & Python

Free on YouTube! Witness the power of Definition Queries in ArcGIS Pro through this comprehensive course that dives managing and utilizing definition queries with spatial data using ArcPy and Python scripting. In this course, we will focus exclusively on Definition Queries, covering their creation, modification, and application through hands-on exercises and real-world scenarios.

Custom Tool Parameters

For this example we will use the two required parameters, your custom tool might have more parameters. The first parameter prompts the user to add an Excel file (.xlsx) as an input. The second parameter is a string that will represent a dropdown list of the available sheet names from the input Excel file. 

List Excel Sheet Names Parameters in Custom Tool in ArcGIS Pro

Custom Tolol Validation

At the top of the validation we import the pandas module. We the add code to the updateParameters function. This function is called whenever an input parameter is updated. If a user has selected an input Excel file, then pandas will access that file and set the dropdown choice list for the second parameter (Sheet Name) to the list all sheet names from the Excel file.

Get Excel Sheet Names tool Validation for ArcGIS Pro Custom Tool

Get Excel Sheet Names Input Parameters in Action

Below I have selected an Excel file as the first user input. The tool validation kicks in an pandas grabs the list of sheet names from the file and ArcPy presents that list as a dropdown for the second parameter.

Get Excel Sheet Names in ArcGIS Pro with ArcPy & Pandas in Action

If you’ve found these blogs helpful and would like to support the project, please consider making a donation. All learning material is provided free of charge to help GIS professionals, students, and developers learn ArcPy, the ArcGIS API for Python, ArcGIS Pro, and ArcGIS Online. Donations help cover website hosting, software licensing, domain costs, and the time involved in creating and maintaining tutorials, courses, and learning resources. Your support helps keep this content freely available to everyone and allows new courses and materials to be developed for the GIS community. If the content has helped you solve a problem, learn a new skill, or advance your career, please consider supporting the project with a donation. Every contribution, no matter the size, is greatly appreciated.

Leave a Comment