<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Looping through Excel Worksheets within a Workbook, then Creating XY points in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1168953#M64426</link>
    <description>&lt;P&gt;I am trying to loop through a bunch of Excel Worksheets within a Workbook and finally creating XY points inside a GDB.&amp;nbsp; It seems what I have done works on the first worksheet only, but it doesn't do anything with the other worksheets.&amp;nbsp; Maybe I have the for loop part wrong since it never gets past first sheet.&amp;nbsp; Any ideas please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

#set local variables
arcpy.env.overwriteOutput = True
xlsxWS = r'C:\Data\working\EBS16\raw_sonar_files'
outGDB = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb"
finalOUT = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb\em710vals\em50_"
arcpy.env.workspace = xlsxWS

lf = arcpy.ListFiles()
try:
    for xlxs in lf:
        arcpy.env.workspace = os.path.join(xlsxWS, xlxs) # sets the arcpro workspace to the workbook
        lTables = arcpy.ListTables() # lists worksheets in the xlsx
        for tab in lTables:
            outFC = tab.replace("$", '') #remove invalid characters from sheet names
            outLyr = outFC + '_lyr' # create name for temp layer in XY event theme
            #if want to create a table
            #arcpy.TableToTable_conversion(tab,outGDB, outFC)
            arcpy.MakeXYEventLayer_management(tab,'easting', 'northing', outLyr)
            outFeat =  finalOUT + outFC # naming convention
            arcpy.management.CopyFeatures(outLyr, outFeat) # make lyr permanent
except Exception as e:
    #dump errors
    print("Error: " + e.args[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2022 17:52:08 GMT</pubDate>
    <dc:creator>ssintelmann</dc:creator>
    <dc:date>2022-04-28T17:52:08Z</dc:date>
    <item>
      <title>Looping through Excel Worksheets within a Workbook, then Creating XY points</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1168953#M64426</link>
      <description>&lt;P&gt;I am trying to loop through a bunch of Excel Worksheets within a Workbook and finally creating XY points inside a GDB.&amp;nbsp; It seems what I have done works on the first worksheet only, but it doesn't do anything with the other worksheets.&amp;nbsp; Maybe I have the for loop part wrong since it never gets past first sheet.&amp;nbsp; Any ideas please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

#set local variables
arcpy.env.overwriteOutput = True
xlsxWS = r'C:\Data\working\EBS16\raw_sonar_files'
outGDB = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb"
finalOUT = r"C:\Data\working\EBS16\EBS_16_analysis_display\default.gdb\em710vals\em50_"
arcpy.env.workspace = xlsxWS

lf = arcpy.ListFiles()
try:
    for xlxs in lf:
        arcpy.env.workspace = os.path.join(xlsxWS, xlxs) # sets the arcpro workspace to the workbook
        lTables = arcpy.ListTables() # lists worksheets in the xlsx
        for tab in lTables:
            outFC = tab.replace("$", '') #remove invalid characters from sheet names
            outLyr = outFC + '_lyr' # create name for temp layer in XY event theme
            #if want to create a table
            #arcpy.TableToTable_conversion(tab,outGDB, outFC)
            arcpy.MakeXYEventLayer_management(tab,'easting', 'northing', outLyr)
            outFeat =  finalOUT + outFC # naming convention
            arcpy.management.CopyFeatures(outLyr, outFeat) # make lyr permanent
except Exception as e:
    #dump errors
    print("Error: " + e.args[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 17:52:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1168953#M64426</guid>
      <dc:creator>ssintelmann</dc:creator>
      <dc:date>2022-04-28T17:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through Excel Worksheets within a Workbook, then Creating XY points</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1168963#M64427</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/441501"&gt;@ssintelmann&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I would recommend using the Excel to Table function to convert the excel sheets.&amp;nbsp; To iterate through an excel workbook to get the sheets, you could use pandas to do this.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
import arcpy, os, re

# Variables
arcpy.env.workspace = r"C:\Projects\Documents"
outputGDB = r"C:\Projects\Data.gdb"

for file in arcpy.ListFiles("*.xlsx"):
    f = os.path.join(arcpy.env.workspace, file)
    # Get excel sheets
    sheetNames = pd.ExcelFile(f).sheet_names

    # iterate through sheets
    for sheet in sheetNames:
        # Replace non alphanumeric characters with underscore
        sheetName = re.sub(r'[^0-9a-zA-Z]+', r'_', sheet)
        # Convert sheet to GDB table
        arcpy.conversion.ExcelToTable(f, os.path.join(outputGDB, sheetName), sheet, 1, '')&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1168963#M64427</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2022-04-28T18:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through Excel Worksheets within a Workbook, then Creating XY points</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1169014#M64428</link>
      <description>&lt;P&gt;Thanks much. That worked perfectly.&amp;nbsp; I am new to Python.&amp;nbsp; I see this uses the re.sub() to replace various characters.&amp;nbsp; In your pattern&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[^0-9a-zA-Z]+&lt;/PRE&gt;&lt;P&gt;what exactly is that doing.&amp;nbsp; Does the '^' indicate do not match the number, or upper and lower case letter pattern for the replacement?&amp;nbsp; Thanks for the lesson, it helped.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 19:23:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1169014#M64428</guid>
      <dc:creator>ssintelmann</dc:creator>
      <dc:date>2022-04-28T19:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through Excel Worksheets within a Workbook, then Creating XY points</title>
      <link>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1169253#M64433</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/441501"&gt;@ssintelmann&lt;/a&gt;&amp;nbsp;here is some info from the &lt;A href="https://docs.python.org/3/library/re.html" target="_self"&gt;help&lt;/A&gt;:&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;P&gt;Characters that are not within a range can be matched by&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;complementing&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;the set. If the first character of the set is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;'^'&lt;/SPAN&gt;, all the characters that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;not&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in the set will be matched. For example,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;[^5]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;will match any character except&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;'5'&lt;/SPAN&gt;, and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;[^^]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;will match any character except&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;'^'&lt;/SPAN&gt;.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;^&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;has no special meaning if it’s not the first character in the set.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN class=""&gt;[^a-zA-Z0-9_]:&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;Matches any character which is not a word character&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 12:49:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-through-excel-worksheets-within-a-workbook/m-p/1169253#M64433</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2022-04-29T12:49:36Z</dc:date>
    </item>
  </channel>
</rss>

