<?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: Table to Excel in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697763#M54075</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It seems to work, unfortunately I don't know how to define the output&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jun 2014 06:57:03 GMT</pubDate>
    <dc:creator>JohnByrne</dc:creator>
    <dc:date>2014-06-19T06:57:03Z</dc:date>
    <item>
      <title>Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697759#M54071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am currently trying to use the Table to Excel script to produce a table of a query that I have created. It returns all the fields not just the selected one. Any ideas? I am sure it is simple&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;John&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:38:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697759#M54071</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2014-06-18T14:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697760#M54072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As far as I understand it, the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000054000000"&gt;Table To Excel tool&lt;/A&gt;&lt;SPAN&gt; will export selected records (not selected fields) to an excel table. If you only want selected field in the excel table, I think you would have to use the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006v000000"&gt;Make Table View tool&lt;/A&gt;&lt;SPAN&gt; before the Table To Excel tool. You could use the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;"field_info"&lt;/SPAN&gt;&lt;SPAN&gt; parameter to pick out your desired fields.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:59:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697760#M54072</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2014-06-18T14:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697761#M54073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Joshua,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for replying, that certainly looks promising. I am actually trying to export the table based on a query I have already ran and linked to Data Driven Pages. How would I refernce that in the Make Table View? I am new to this so please excuse the silly question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have linked my current attempt at the script, which works for the initial part of what I am trying to achieve, just failing at the output.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached my script so you can maybe see it easier.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 15:07:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697761#M54073</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2014-06-18T15:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697762#M54074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def table_to_excel(in_table, output, use_field_alias=False, use_domain_desc=False):
&amp;nbsp;&amp;nbsp;&amp;nbsp; desiredFields=["Field1","Field3","Field8"] #desired fields for excel output

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the fields from the input
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields= arcpy.ListFields(in_table)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a fieldinfo object
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo = arcpy.FieldInfo()

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Iterate through the fields and set them to fieldinfo
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field in desiredFields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo.addField(field.name, field.name, "VISIBLE", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # The created crime_view layer will have fields as set in fieldinfo object
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(in_table, "table_view", "", "", fieldinfo)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # To persist the layer on disk make a copy of the view
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToExcel_conversion("table_view", output)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that I couldn't fully test it because I'm still on 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if it works!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:21:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697762#M54074</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-12T05:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697763#M54075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It seems to work, unfortunately I don't know how to define the output&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 06:57:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697763#M54075</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2014-06-19T06:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697764#M54076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This a view of the amended code, as per your advice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import xlwt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd=arcpy.mapping.MapDocument("current")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BUSID_TEMP=arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LayersDF=arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;selLyr=arcpy.mapping.ListLayers(mxd, "FP_sample", LayersDF)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for elm in arcpy.mapping.ListLayoutElements(mxd):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name=="GridTable": GridTable = elm&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp=mxd.dataDrivenPages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(BUSID_TEMP)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pageID=mxd.dataDrivenPages.getPageIDFromName(str(BUSID_TEMP))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.dataDrivenPages.currentPageID=pageID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#excel export part of the script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def table_to_excel(FP_sample, output, use_field_alias=False, use_domain_desc=False):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; desiredFields=["Field1","Field3","Field4"] #desired fields for excel output&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the fields from the input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fields= arcpy.ListFields(in_table)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a fieldinfo object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo = arcpy.FieldInfo()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Iterate through the fields and set them to fieldinfo&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field in desiredFields:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo.addField(field.name, field.name, "VISIBLE", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # The created view layer will have fields as set in fieldinfo object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(FP_sample, "table_view", "", "", fieldinfo)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # To persist the layer on disk make a copy of the view&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToExcel_conversion("table_view", pop.xls)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 07:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697764#M54076</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2014-06-19T07:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697765#M54077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sorry if I was unclear, but I have some corrections for your script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;In the line &lt;SPAN style="font-style: italic; text-decoration: underline;"&gt;desiredFields=["Field1","Field3","Field4"]&lt;/SPAN&gt;, you should specify the fields by their name (not their position or alias). This line should be something more like &lt;SPAN style="font-style: italic; text-decoration: underline;"&gt;desiredFields=["CityName","Pop","Province"]&lt;/SPAN&gt; or whatever fields you want to include. I'm sorry I was unclear on that line.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In the script you posted (TableToExcelJB.py), the defined method "table_to_excel" takes 2 inputs ("in_table", "output") and 2 optional inputs ("use_field_alias", "use_domain_desc"). This is all stated in the line &lt;SPAN style="font-style: italic; text-decoration: underline;"&gt;def table_to_excel(in_table, output, use_field_alias=False, use_domain_desc=False):&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;This defined method is called (and run) from this line (at the bottom of the script): &lt;SPAN style="font-style: italic; text-decoration: underline;"&gt;table_to_excel(arcpy.GetParameterAsText(0),arcpy.GetParameterAsText(1),arcpy.GetParameter(2),arcpy.GetParameter(3))&lt;/SPAN&gt;.&lt;BR /&gt;This means the output is being defined by the user in a tool. If you want to 'hardcode' the output location, specify it like this:&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;output=r"C:\Path\To\pop.xls"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;LI&gt;In further looking at the script (TableToExcelJB.py) you provided, it looks like it was designed to handle your data is a special way, reformatting some data as it runs. I'm worried a more spimlified version of this script (as I provided) will not handle your data in the same way the TableToExcelJB.py script does. Is this a problem?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 13:45:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697765#M54077</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2014-06-19T13:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697766#M54078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just a thought, if the table is in ArcMap and you hide the fields you don't want, then export the file...do you get the results you want?&amp;nbsp; If you are working with a file on disk, all fields will get exported&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 13:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697766#M54078</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-06-19T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Table to Excel</title>
      <link>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697767#M54079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Dan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am going to have a play with your advice now. Essentially my problems are (many but will simplify)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. I need to create datadriven pages from a specific query, which I have managed to do at the minute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. The results of this query needs to be also shown in a seperate table hence why I am trying to export it to Excel. We have had a look at using Production mapping but there are too many varied results between queries to maintain a consistent look.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. I am unsure, due to my inexperience if I should be changing the input and out when it appears in the script to get the results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that makes sense and thanks for your help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 14:11:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-to-excel/m-p/697767#M54079</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2014-06-19T14:11:54Z</dc:date>
    </item>
  </channel>
</rss>

