<?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 Re: Query the fields of an attribute table of a .shp file (ArcMap) from an .xlsm file with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1065493#M61301</link>
    <description>&lt;P&gt;I got this code as a solution to the post&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import openpyxl as px

def main():
    wb = px.load_workbook(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsm", read_only=False, keep_vba=True)
    ws = wb['VINCULACION_SH_NUE']
    in_features = r"C:\Users\Hp\Desktop\Ejemplo\VH_Dissolve.shp"

    row_num = 3
    with arcpy.da.SearchCursor(
        in_features,
        ["COLOR", "INTERNO_DE", "CLASE_DEMA", "COUNT_AREA", "SUM_AREA", "SUM_LENGTH"],
    ) as cursor:
        for row in cursor:
            ws.cell(row=row_num, column=2).value = row[0]
            ws.cell(row=row_num, column=3).value = row[1]
            ws.cell(row=row_num, column=4).value = row[2]
            ws.cell(row=row_num, column=6).value = row[3]
            ws.cell(row=row_num, column=7).value = row[4]
            ws.cell(row=row_num, column=8).value = row[5]
            row_num += 1
    wb.save(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsm")&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 08 Jun 2021 14:54:09 GMT</pubDate>
    <dc:creator>BriamR</dc:creator>
    <dc:date>2021-06-08T14:54:09Z</dc:date>
    <item>
      <title>Query the fields of an attribute table of a .shp file (ArcMap) from an .xlsm file with Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064690#M61282</link>
      <description>&lt;P&gt;I would like to know if there is any way through Python to query the fields of an attribute table of a .shp file (ArcMap) from an .xlsm file (Excel with macros enabled), this since what I currently do repetitively and manual is to copy the attribute table from ArcMap to my Excel file "VINCULACION_S.xlsm".&lt;/P&gt;&lt;P&gt;One of the attribute tables that I want to copy is the one I show in this image,&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JosephBriamRamonRodriguez_1-1622745004422.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/15085i14CCA886922C2DF8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JosephBriamRamonRodriguez_1-1622745004422.png" alt="JosephBriamRamonRodriguez_1-1622745004422.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Towards the .xlsm file already mentioned, which I show in this image.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JosephBriamRamonRodriguez_0-1622744959302.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/15084i1DF90A64ED323894/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JosephBriamRamonRodriguez_0-1622744959302.png" alt="JosephBriamRamonRodriguez_0-1622744959302.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a good start apparently&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# Set local variables

inTable = outTable

outXLS = VHFolder + "/Vinculacion_S.xlsx" #this is where I had to give the file path and then the file name

# Execute TableToExcel

arcpy.TableToExcel_conversion(inTable, outXLS)

ersion(inTable, outXLS)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 18:30:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064690#M61282</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-03T18:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064699#M61283</link>
      <description>&lt;P&gt;Please explain "&lt;SPAN&gt;&lt;STRONG&gt;query the fields of an attribute table of a .shp file (ArcMap) from an .xlsm file&lt;/STRONG&gt;&amp;nbsp;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What do you want to do?&amp;nbsp; Cursor though the excel file and see if some values exist in the attribute table?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:57:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064699#M61283</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-06-03T15:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064703#M61285</link>
      <description>&lt;P&gt;The &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/conversion-toolbox/excel-to-table.htm" target="_self"&gt;documentation&lt;/A&gt; says&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Excel Workbooks (.xlsx) and Microsoft Excel 5.0/95 Workbook (.xls) formats are supported as input.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;A quick test with an .xlsm file seems to support this. ArcMap doesn't even show the&amp;nbsp;.xlsm file to interact with. You'll have to save the Excel file as a supported format.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 16:03:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064703#M61285</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-03T16:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064710#M61286</link>
      <description>&lt;P&gt;I just tested changing the file extension from xlsm to xlsx and ArcMap was able to read the data. If you're comfortable, you could use Python to change the file extension, read the data, then change the file extension back when finished.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 16:08:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064710#M61286</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-03T16:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064718#M61287</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt;&amp;nbsp; Thanks for your interest in my post&lt;/P&gt;&lt;P&gt;What I want to do is query the fields of a .shp file from an excel .xlsm file, that is, avoid the repetitive and manual process of copying the attribute table from arcmap to the working .xlsm file,&lt;BR /&gt;&lt;BR /&gt;For example, query and write the values ​​of this attribute table displayed in arcmap and contained in the VHDissolve353.shp file from my Excel VINCULACION.xlsm file&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-06-03 110625.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/15066i3A1D09BB5A8865AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2021-06-03 110625.png" alt="Screenshot 2021-06-03 110625.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-06-03 110738.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/15067i5E53EC8CA3B788CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2021-06-03 110738.png" alt="Screenshot 2021-06-03 110738.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note: The attribute table and the table in excel have the same fields.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp; The process that you propose to me in python sounds interesting, could you help me with the way or an example to be able to achieve it.&amp;nbsp;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 16:22:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064718#M61287</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-03T16:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064787#M61288</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/468951"&gt;@BriamR&lt;/a&gt;&amp;nbsp;wrote:&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp; The process that you propose to me in python sounds interesting, could you help me with the way or an example to be able to achieve it.&amp;nbsp;Thank you&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="https://www.tutorialspoint.com/How-to-change-file-extension-in-Python" target="_self"&gt;Here's a snippet&lt;/A&gt; to change the file extension with Python. I would put that in a try/finally block to ensure it gets changed back to the correct file extension when the script exits.&lt;/P&gt;&lt;P&gt;However, I'm still not completely clear on what exactly you're trying to do. Are you updating the fields of existing records in the shapefile or creating new records? If they are new records, what are you using for geometry (X,Y)?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 18:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064787#M61288</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-03T18:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064795#M61289</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp; The idea is to perform a query in the SHP file and write the results of the query in an existing Excel file. Note: update the question, attaching the .shp and .xlsm files.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 22:22:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064795#M61289</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-03T22:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064802#M61290</link>
      <description>&lt;P&gt;So your taking data from the shapefile and writing it to Excel? Can it be a new Excel file or do you have to write it into the existing Excel file?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 18:31:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064802#M61290</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-03T18:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064806#M61291</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Yes, I take the data from the .shp to write it in the .xlsm, the excel book is always an existing file.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;To get the .shp file, I export it from an AutoCAD MAP 3D drawing, then work it in ArcMap. Now the query I am looking for is to take the table attributes from the .shp file to add them to an already existing Excel file "VINCULACION_S.xlsm"&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 19:10:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064806#M61291</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-03T19:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Consult ArcMap attribute table or shapefile file (.shp) from Excel (.xlsm) through Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064877#M61293</link>
      <description>&lt;P&gt;In that case, you'll probably have to use a library like &lt;A href="https://openpyxl.readthedocs.io/en/stable/" target="_self"&gt;OpenPyXL&lt;/A&gt; to write to the existing Excel file. I've never done that so you'll have to explore that on your own. Start with a&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/searchcursor-class.htm" target="_self"&gt;SearchCursor&lt;/A&gt; on the shapefile using a where_clause to query on the records you want. Then iterate over the SearchCursor and find a way to&amp;nbsp;&lt;A href="https://openpyxl.readthedocs.io/en/stable/usage.html#write-a-workbook" target="_self"&gt;write the rows to Excel&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 21:09:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1064877#M61293</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-03T21:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Query the fields of an attribute table of a .shp file (ArcMap) from an .xlsm file with Python</title>
      <link>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1065493#M61301</link>
      <description>&lt;P&gt;I got this code as a solution to the post&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import openpyxl as px

def main():
    wb = px.load_workbook(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsm", read_only=False, keep_vba=True)
    ws = wb['VINCULACION_SH_NUE']
    in_features = r"C:\Users\Hp\Desktop\Ejemplo\VH_Dissolve.shp"

    row_num = 3
    with arcpy.da.SearchCursor(
        in_features,
        ["COLOR", "INTERNO_DE", "CLASE_DEMA", "COUNT_AREA", "SUM_AREA", "SUM_LENGTH"],
    ) as cursor:
        for row in cursor:
            ws.cell(row=row_num, column=2).value = row[0]
            ws.cell(row=row_num, column=3).value = row[1]
            ws.cell(row=row_num, column=4).value = row[2]
            ws.cell(row=row_num, column=6).value = row[3]
            ws.cell(row=row_num, column=7).value = row[4]
            ws.cell(row=row_num, column=8).value = row[5]
            row_num += 1
    wb.save(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsm")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Jun 2021 14:54:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/query-the-fields-of-an-attribute-table-of-a-shp/m-p/1065493#M61301</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-08T14:54:09Z</dc:date>
    </item>
  </channel>
</rss>

