<?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: Exporting selected attributes to excel in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097800#M62375</link>
    <description>&lt;P&gt;I was able to get this to work but I had to us the arcpy.CopyFeatures_management which is ok I guess but I would like to skip this part if possible?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if int(arcpy.GetCount_management(selection).getOutput(0)) &amp;gt; 0:
    arcpy.MakeFeatureLayer_management(selection, "SelectLyr")
    arcpy.CopyFeatures_management("SelectLyr", "C:\Temp\Scratchworkspace.gdb\Tempselect")

fc = "C:\Temp\Scratchworkspace.gdb\Tempselect"
desc = arcpy.Describe(fc)

flds = [fld.name for fld in desc.fields]
flds_remove = [desc.OIDFieldName,  
                desc.shapeFieldName,  
                desc.areaFieldName,
                desc.LengthFieldName]  
for fld in flds_remove:  
    flds.remove(fld)
file = folder = os.path.dirname(mxd.filePath)+ "/" + "tmp_view"
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)

wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'  

arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Listing' + OutputExt)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 21:03:33 GMT</pubDate>
    <dc:creator>2Quiker</dc:creator>
    <dc:date>2021-09-13T21:03:33Z</dc:date>
    <item>
      <title>Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097241#M62344</link>
      <description>&lt;P&gt;I need to be able to export the selected attributes from Arcmap. I have the following but I get an error on line 32. The first arcpy.Addmessage does print the OID's but not the second Addmessage. My guess is that it's not creating the temp_view. How can I get past this error?&lt;/P&gt;&lt;P&gt;error on line 32&lt;/P&gt;&lt;P&gt;ERROR 000732: Input Table: Dataset tmp_view does not exist or is not supported&lt;BR /&gt;Failed to execute (TableToExcel)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selection = "NParcels"

try:
    if int(arcpy.GetCount_management(selection).getOutput(0)) &amp;gt; 0:
        
        arcpy.CopyRows_management(selection, "selct")
        arcpy.MakeTableView_management("selct","selectionView")

        fc = "selectionView"
        desc = arcpy.Describe(fc)
        oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
        arcpy.AddMessage(oidList)
        flds = [fld.name for fld in desc.fields]
        flds_remove = [desc.OIDFieldName,  
                      desc.shapeFieldName,  
                      desc.areaFieldName,
                      desc.LengthFieldName]  
        for fld in flds_remove:  
            flds.remove(fld)   
        arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)
        oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
        arcpy.AddMessage(oidList)
except:
    pass

wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'  

arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Notification' + OutputExt)&lt;/LI-CODE&gt;&lt;P&gt;K&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 15:37:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097241#M62344</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-09-10T15:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097247#M62345</link>
      <description>&lt;P&gt;I'd as some exception handling to your except as it's very likely that something is wrong in the try block, the except does nothing and then tmp_view is called when it doesnt exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Personally I would get rid of the try except and any arcpy.getparameter stuff until you're sure the code works.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 15:49:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097247#M62345</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-10T15:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097309#M62347</link>
      <description>&lt;P&gt;I removed the try block. I get the following error,&lt;/P&gt;&lt;P&gt;ERROR 000055: Cannot create a Query Table for this workspace&lt;BR /&gt;Failed to execute (MakeQueryTable).&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 18:04:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097309#M62347</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-09-10T18:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097354#M62348</link>
      <description>&lt;P&gt;Just a guess from looking at the docs, but fields argument seems to require a list of lists, something like&lt;/P&gt;&lt;P&gt;[&amp;nbsp; [field1], [field2] ...&amp;nbsp; ]&lt;/P&gt;&lt;P&gt;maybe:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        flds = [[fld.name] for fld in desc.fields]
        flds_remove = [[desc.OIDFieldName],  
                      [desc.shapeFieldName],  
                      [desc.areaFieldName],
                      [desc.LengthFieldName]] &lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 10 Sep 2021 19:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097354#M62348</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-10T19:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097729#M62370</link>
      <description>&lt;P&gt;I did have the following but I kept giving me errors like the following, so I removed them.&lt;/P&gt;&lt;P&gt;[desc.shapeFieldName],&lt;BR /&gt;AttributeError: DescribeData: Method shapeFieldName does not exist&lt;/P&gt;&lt;P&gt;[desc.shapeFieldName],&lt;BR /&gt;AttributeError: DescribeData: Method areaFieldName does not exist&lt;/P&gt;&lt;P&gt;[desc.shapeFieldName],&lt;BR /&gt;AttributeError: DescribeData: Method desc.LengthFieldName does not exist&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;flds_remove = [desc.OIDFieldName,
desc.shapeFieldName,
desc.areaFieldName,
desc.LengthFieldName] &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am thinking that the arcpy.MakequeryTable_management is not working because I don't get a list of OID after but I am not sure why.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 17:48:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097729#M62370</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-09-13T17:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097800#M62375</link>
      <description>&lt;P&gt;I was able to get this to work but I had to us the arcpy.CopyFeatures_management which is ok I guess but I would like to skip this part if possible?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if int(arcpy.GetCount_management(selection).getOutput(0)) &amp;gt; 0:
    arcpy.MakeFeatureLayer_management(selection, "SelectLyr")
    arcpy.CopyFeatures_management("SelectLyr", "C:\Temp\Scratchworkspace.gdb\Tempselect")

fc = "C:\Temp\Scratchworkspace.gdb\Tempselect"
desc = arcpy.Describe(fc)

flds = [fld.name for fld in desc.fields]
flds_remove = [desc.OIDFieldName,  
                desc.shapeFieldName,  
                desc.areaFieldName,
                desc.LengthFieldName]  
for fld in flds_remove:  
    flds.remove(fld)
file = folder = os.path.dirname(mxd.filePath)+ "/" + "tmp_view"
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)

wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'  

arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Listing' + OutputExt)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 21:03:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1097800#M62375</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-09-13T21:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting selected attributes to excel</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1099392#M62450</link>
      <description>&lt;P&gt;I am still trying how to figure out how do this without the Copymanagment.&lt;/P&gt;&lt;P&gt;I was able to do it with the arcpy.da.FeatureClassToNumPyArray but it exported all the fields I need to remove the extra fields like the OID, area and length fields.&lt;/P&gt;&lt;P&gt;I have the following but it's still including those extra fields. I get the following error.&lt;/P&gt;&lt;P&gt;DescribeData: Method lengthFieldName does not exist&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selection = "NParcels"
if int(arcpy.GetCount_management(selection).getOutput(0)) &amp;gt; 0:
    arcpy.MakeTableView_management(selection, "NP_VIEW")

    fc1 ="NP_VIEW"
    dsc = arcpy.Describe(fc1)
    fields = dsc.fields
    out_fields = [dsc.OIDFieldName, dsc.lengthFieldName, dsc.areaFieldName]
    fieldnames = [field.name for field in fields if field.name not in out_fields]

    nparr = arcpy.da.FeatureClassToNumPyArray(fc1, fieldnames)
    arcpy.TableToExcel_conversion(fc1, "C:/temp/Test.xls")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 15:24:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attributes-to-excel/m-p/1099392#M62450</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-09-17T15:24:01Z</dc:date>
    </item>
  </channel>
</rss>

