Exporting Selected Records from Feature Layer to .CSV File?

6374
14
12-20-2013 06:52 AM
IanPeebles
Occasional Contributor III
I am interested in adding in functionality that allows the user to select records from a feature layer and then have them export them to a .csv file.  I checked the JS API and samples and did not see this functionality.  I do not want a shapefile or feature class exported, just a table.  Users who will be using this will not have an ArcGIS Desktop install.

Has anyone been able to get something like this to work?  Would be very interested in your ideas.  Thanks.
0 Kudos
14 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Ian,

Attached is a toolbox with an added python script.  The script will export a table, or feature class's table, to a CSV or XLS file.  You can publish this as an ArcGIS Server GP Service, and then use the Geoprocessor class to run this in your application.
0 Kudos
GaneshSolai_Sambandam
New Contributor III
Hi Jskinner
Thank you for ARCPY script. Unfortunately, when I try to run your model in ARCGtool box with my sample featureclass or shapefile,
I am getting the following error. I changed the data input parameter setting to featureclass and output data type to derived.



<class 'pywintypes.com_error'>:(-2147221005, 'Invalid Class String', None, None).
Failed to excute
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You won't have to make any changes to the parameters.  The script should run on a feature class with the input as a 'Table View' and the output type as 'Required'.
0 Kudos
IanPeebles
Occasional Contributor III
Thanks for the script.  I just want to clarify. . this will work within a javascript application using a feature layer correct?  You mentioned feature class, which tells me that this will work for a desktop application?

I will have selection tools that will select the feature layer within the application.  Are you saying I can create a geoprocessing service that I can run to export the selected records within the application?

If so, I will try this out when I return to the office next week.  I am out of the office, so I cannot test until next week.
0 Kudos
GaneshSolai_Sambandam
New Contributor III
Hi Jskinner
This time, I didn't change of your code and just used it.
for input data type - i chose "Table View" - required
for output data type - i chose "File" - required.

But, still I am getting same error as mentioned above.


<class 'pywintypes.com_error'>-2147221005, 'Invalid Class String', None, None).
Failed to excute


Finally, I looked at your code, the input and output files are  is hard coded.
Something like this:
tablePath = r"C:\TEMP\Python\Test.gdb\XY"
filePath = r"C:\TEMP\Python\XY.xlsx"

So, In this case, it won't work I believe.
Inorder to get user input and output files - should we not use something like this:
inputFile = arcpy.GetParameterAsText(0)
outputFile = arcpy.GetParameterAsText(0)


If I am wrong please correct me.

Regards
Ganesh
0 Kudos
JakeSkinner
Esri Esteemed Contributor
That was my mistake.  I sent the wrong script.  I've attached the correct one.
0 Kudos
JohnRitsko1
New Contributor III

Was looking for a recent solution to this and I downloaded your python and attempted to publish and it simply crashes in Catalog when trying to publish.  I have tried looking into the Export Item as well with no luck on how to set that up either.  If you can provide some insight into setting this up that would be greatly appreciated.  If not I'll start a new question.  Thank you.

0 Kudos
GaneshSolai_Sambandam
New Contributor III
HI Jskinner
Can you also explain the output datatype for your parameter, please.


Regards
Ganesh
0 Kudos
IanPeebles
Occasional Contributor III
That was my mistake.  I sent the wrong script.  I've attached the correct one.


How can I use this tool for the Javascript application?  For instance, I want to be able to select records and just export those records to a .csv file.

I need this to work against a feature service.  How do I use this tool with a feature service?

Is this more of an ArcGIS Desktop tool?
0 Kudos