Select to view content in your preferred language

FeatureDataGrid Excel Export

2479
6
02-25-2011 08:40 AM
DavidAshton
Frequent Contributor
I was looking for an example/sample code showing how to export the information from FeatureDataGrid to an Excel file.  I came across this post, which has a link to another post that shows how to export the DataGrid to an Excel but it doesn't seem to work for a FeatureDataGrid

http://forums.arcgis.com/threads/13460-Export-to-Excel...?p=79906#post79906


I was wondering if anyone has accomplished this and would like to help me out and maybe share some code or had any ideas / research tips and information .

Thanks
David
0 Kudos
6 Replies
DarinaTchountcheva
Frequent Contributor
Hi David,

I guess, I never took the time to revisit the thead you referred to. Guilty!

I am attaching a solution file, with a very simplified Export to excel, using the FeatureDataGrid sample from the Gallery.

It covers exporting all the features in the grid (FeatureLayer), the selected graphics, and exporting all the graphics but only a few of the attributes with their aliases.

Please, don't be confused by the name of the solution, I just used an old project to test the export to Excel.

Please, fix the ESRI assembly references. I had to remove them from the bin, because the zip was too big.

There is a line of code in App.xaml.cs, which you should include in your project if you don't want your app to crash if user tries to save over an open Excel file. And you can find your own solution for this, if you don't like mine (I don't like it either, but I am solving problems one by one, so some have to wait. 🙂 )

Good luck!

Let me know if something is not working for you. Hope, we will be able to resolve it.

Darina
0 Kudos
EricCreahi
Emerging Contributor
Hi! I use your code and i have erro:

Please can you help me !
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi! I use your code and i have erro:

Please can you help me !

I guess you should check that your attribute is set:

var key = field.Header.ToString();
if (data.Attributes.ContainsKey(key))
    strValue = data.Attributes[key].ToString();
0 Kudos
EricCreahi
Emerging Contributor
Hi thanks for your reponse.
But it is the same problem.
i use this FeatureLayer :Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0"

I can export the first attribut :OBJECTID (Type: esriFieldTypeOID, Alias: Object Id)
But the other one has the same problem.
And i use your last code nothing.


Please help me 😞
0 Kudos
EricCreahi
Emerging Contributor
May be we have some Null
0 Kudos
EricCreahi
Emerging Contributor
okay, I found the mistake.
 <esri:FeatureDataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding OBJECTID}" Header="OBJECTID"/>
                <sdk:DataGridTextColumn Binding="{Binding Tsu}"  Header="Tsu"/>
                <sdk:DataGridTextColumn Binding="{Binding Magnitude}" Header="Magnitude"/>
            </esri:FeatureDataGrid.Columns>

we have space in the header, For instance: Header="OBJECTID Hello" .
the good one is Header="OBJECTIDHello" without  space.
Thanks
0 Kudos