How to export attributes to excel

3569
14
02-15-2011 05:51 AM
DonFreeman
New Contributor
Can someone point me to instructions on how to export a FeatureLayer's attribute table to an excel or CSV file?
Thanks
0 Kudos
14 Replies
JMcNeil
Occasional Contributor III
I have a python scipt to export selected records from a GP service/task to a excel and then I serve the excel up as a zip download.  Not exactly what you need and not as clean as you want it to be but say the word and it is yours!
0 Kudos
DonFreeman
New Contributor
I have a python scipt to export selected records from a GP service/task to a excel and then I serve the excel up as a zip download.  Not exactly what you need and not as clean as you want it to be but say the word and it is yours!


Hmmm. . .
And this can be triggered from a Silverlight page?
Actually, I already have a routine that I like but which requires a data context. I don't know how to create a data context for my FeatureLayer. I'm still too new to all this stuff. (shrug)
0 Kudos
DavidAshton
Occasional Contributor III
dfreeman2005
Have you seen this post? 
http://forums.arcgis.com/threads/13460-Export-to-Excel...?p=79906#post79906

I'm trying to get this code working and was wondering if you saw this and/or if you have had any success with your efforts.

Dave
0 Kudos
DonFreeman
New Contributor
Hmmm. . .
And this can be triggered from a Silverlight page?
Actually, I already have a routine that I like but which requires a data context. I don't know how to create a data context for my FeatureLayer. I'm still too new to all this stuff. (shrug)


No success yet. We broke the SQL/SDE install so right now that has my attention. (groan)
0 Kudos
pavankalvala
New Contributor
I am trying to export attributes of a feature to MS word. I created a Microsoft word template with a table that has attribute field names to the left and onto the right, I would like to pass the values that are related to that field in Word.

Please let me know.

I Created a .dot template and would like to pull data from attribute table to this word document.

here is what I did so far:

          //Start Word and create a new document.
           Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
           
            //start word template
            object oTemplate = "c:\\Mobile projects\\Annual Patrol Form 2010 final.dot";
            oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
                ref oMissing, ref oMissing);

Please guide me.
Thanks
0 Kudos
DonFreeman
New Contributor
Looks like you are trying to do it with automation. I have not done it with ESRI but in other environments I do it this way:

1. Design your template with bookmarks where you want the fields to be placed.
2. Then open the template and make it the active document as you describe above.
3. Select the bookmark and place the data into it like this:
 .ActiveDocument.Bookmarks("TCTime").select
 .selection.TypeText(transform(pei.tctime))

In this example pei is the tablename and tctime is the field. This is VB but C# should be similar.
Good luck.
0 Kudos
pavankalvala
New Contributor
Thanks Don for your reply.

I do not have any table to populate into the word template. Since I need to run my code through ESRI ArcMap, I was thinking to first export attribute data to an excel file and then populate field values from that excel file to word template bookmark.

Would there be any proper c# code that helps me to pull data from excel file into the Word bookmarks?

Let me know if there is any other way.

Thanks.
0 Kudos
DonFreeman
New Contributor
You can read the data out of excel if you know what cell the data you want is in, but that sounds terribly convoluted. Why not skip the excel part and read it directly out of the attribute data. How are you getting a hook to the data in esri? If you have access to plug it into excel then you should also have access to plug it into Word. Just loop through the fields and plug them into your template.

If you really want to work with excel you can do something like this.
oX = createobject('Excel.Application')
oX.visible = .t.
oX.Workbooks.open(filename)
oBook = oX.Workbooks(1)
oSheet = oBook.Worksheets(sheetnumber)
myvariable = oSheet.range('B2').value

After that you can do whatever you want with the variable. The above is foxcode but you should be able to convert it to C# fairly easy.
0 Kudos
pavankalvala
New Contributor
Hi Don,

1. I first converted the attribute table to Excel sheet and saved it onto my local ("C:\Documents  
   and Settings\username\exportexcel.xls").
   My Excel sheet looks like this for example:
           A               B                    C
  1      FID        OBJECTID         LANDKEY
  2      0            558300          AZ145

    *** the excel sheet name is "sheet1"
    *** the excel is saved as Exportexcel.xls

2. I created a word document and saved it into (C:\Documents and Settings\username\test.doc")
3. I made a bookmark called "abc" in this doc.
3. Now I want ObjectID value "558300" from Excel to populate in word bookmark "abc".

I am currently testing this in VBA and this is what I have so far. I am calling CreateWordreport from a button click.

Sub createWordReport1()
Dim ExApp As Excel.Application
Dim wdApp As Word.Application

Set ExApp = New Excel.Application
Set wdApp = New Word.Application

'With wdApp
'.Visible = True
'.WindowState = wdWindowStateMaximize
'End With

ExApp.Workbooks.Open ("C:\Documents and Settings\username\exportexcel.xls")
wdApp.Documents.Open ("C:\Documents and Settings\username\test.doc")

'wdApp.ActiveDocument.Bookmarks.Value = ExApp.ActiveWorkbook.Sheets("Sheet1").Range("b2").Value    '// I tried this, but i dont know if this is correct

wdApp.ActiveDocument.Bookmarks("LANDKEY").Select
wdApp.Selection.TypeText (Transform(Sheet1.LANDKEY))
End Sub

Please correct me.
Thanks.
0 Kudos