Thursday, October 17, 2013

How to Create an Export to Excel Button for Any List & View (Including Surveys)

This tutorial will cover how to create a simple HTML button which will export a particular list & list view to Excel.

Materials Needed:

<input type="button" style="width:180px; height: 75px; 30px;background:gray; color:white;font-size:larger; font-weight:bold;"onclick="window.location.href='SITEURL/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={YOUR LIST ID}&View={YOUR VIEW ID}&CacheControl=1';" value ="YOUR BUTTON TEXT"/>

The code above is essentially everything that you will need for a simple Excel Export button.  In order to get the code to work, you will need to update the SITEURL, YOUR LIST ID, YOUR VIEW ID, & YOUR BUTTON TEXT.

The hardest part of this exercise is to determine what your list & view ID are, but even that is simple!

To Obtain Your List & View ID:

1.    Navigate To Your List

2.    Select List Settings

3.    Under Views

a.    Edit the view you would like to create an export button for

4.    Copy The URL from your browser

a.    It should resemble: SitePath/_layouts/ViewEdit.aspx?List=%7B58B38FF2%2D9F99%2D4279%2DA22C%2DA2CCA95F4D7E%7D&View=%7B5781F798%2DD539%2D4015%2D87FB%2DA4A32925AACC%7D&Source=%252Fsites%252Fustsm%252F%255Flayouts%252Flistedit%252Easpx%253FList%253D%25257B58B38FF2%25252D9F99%25252D4279%25252DA22C%25252DA2CCA95F4D7E%25257D

b.    You can manually break out the View= & List=, but I personally just use this free translator that is embedded in the page which does it for you.


To Implement The Button:

1.    Swap out the necessary snippets in order to update the HTML code (YOUR BUTTON TEXT, YOUR URL, YOUR LIST ID, and YOUR VIEW ID) with the information you obtained in “To Obtain Your List & View ID.”

2.    Place the updated code into a text file and save it out on your site

3.    On a webpage that you would like the button, create a content editor web part and link that web part to the URL of your text file, I would recommend using the relative path (/local/fakesite/library/filename.etc).

That’s It Folks!