I am creating a Python script tool in ArcMap to help automate some GIS tasks. The script takes an Excel file( that has Lat/Long fields with values) as the first input parameter. The second parameter takes an output gdb as an argument. The third parameter is the featureclass name being output into the gdb.

I am having trouble understanding how to integrate the users input from these parameters into the main part of the script. In the main function within the script tool, all the processing on the Excel file, its conversion into to a table, the creation of a feature class from that table, and it's projection to WGS84 web auxiliary sphere happen. Part of my script is utilizing code from the example in "Excel to Table(Conversion) for ArcGIS Pro documentation page which is located here. The code in the example creates a data table in a gdb from an Excel file input. The example code goes up to print('Converting {} to {}'.format(sheet, out_table))" and the rest of the code I added.

import os
import xlrd
import openpyxl
import arcpy

in_excel = arcpy.GetParameterAsText(0)
output_gdb = arcpy.GetParameterAsText(1)
fc_name = arcpy.GetParameterAsText(2)

def importallsheets(in_excel, out_gdb):
    if in_excel.endswith(".xlsx"):
        workbook = openpyxl.load_workbook(in_excel)
        sheets = workbook.sheetnames
    elif in_excel.endswith(".xls"):
        workbook = xlrd.open_workbook(in_excel)
        sheets = [sheet.name for sheet in workbook.sheets()]
        print("An Excel Workbook of format .xls or .xlsx is required.")

    print('{} sheets found: {}'.format(len(sheets), ','.join(sheets)))
    for sheet in sheets:
        # The out_table is based on the input Excel file name
        # an underscore (_) separator followed by the sheet name
        out_table = os.path.join(
                "{0}_{1}".format(os.path.basename(in_excel), sheet),

        print('Converting {} to {}'.format(sheet, out_table))

        arcpy.AddMessage("Perform the conversion, store in variable")
        table = arcpy.conversion.ExcelToTable(in_excel, out_table, sheet)
        arcpy.AddMessage("Creating variable for Spatial Reference")
        sr = arcpy.SpatialReference(4269)
        arcpy.AddMessage("Creating Feature layer from table")
        fl = arcpy.MakeXYEventLayer_management(table, "Long", "Lat", Featureclass, sr)
        arcpy.AddMessage("Creating featureclass from feature layer")
        fc = arcpy.FeatureClassToFeatureClass_conversion(fl, outLocation, outFeatureClass, expression)
        arcpy.AddMessage("Projecting layer into WGS84")
        projected_fc = arcpy.Project_management(fc, outgdb, arcpy.SpatialReference(3857))
        arcpy.AddMessage("Your Featureclass {0} is now projected and stored in {1}".format(projected_fc,out_gdb))

How do I utilize the users input given from the script parameters so that my function can use that info and output a projected featureclass?

  • Your code doesn't make any attempt to add a parameter or use it. Since it does take other parameters, and uses them, you probably want to take a stab at this.
    – Vince
    Jan 21, 2023 at 2:35
  • You define your importallsheets function but never actually call it.
    – user2856
    Jan 21, 2023 at 4:59


Your Answer

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

Browse other questions tagged or ask your own question.