sreenu kolusu

sreenu kolusu

  • NA
  • 38
  • 181k

Excel Services Rest API in SharePoint 2010 example

Aug 9 2012 2:16 PM
1. Create sample excel file for sales report.

Get my excel sheet from here.


2. Now upload this file to document library here am uploading to SalesReports document library.

3. Now you can use REST API to get data and charts from excel file.
The following steps shows how to write URLs to get excel file data and charts using REST api and after that how to display excel file Charts in SharePoint. 

Basic URL looks like this:

http://<servername>:<portnumber>/_vti_bin/ExcelRest.aspx/<documentlibrary where excel file is available>/<Name of the excel file>/model

Here my URL
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/

and will get output like 
4. Now i want to know what are the tables available in my excel sheet and you can know  table names(see image). 

URL for that one is:
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Tables

5. Now i want to display table.

URL for that one is:
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Tables('SalesTable')

NOTE:
aslo we can change tables URLs output format to atom but not for charts
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Tables('SalesTable')?$format=atom

but default format for tables is html

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Tables('SalesTable')?$format=html

and

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Tables('SalesTable')

both the URLs are same.
6. Now i wanna know what are the charts available in my excel file. for that URL is 

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Charts



7. Now i want to get charts.
In the excel file  have two charts

I. for first chart, use the following URL
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Charts('AllCitiesChart').


II. for second chart, user the following URL

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Charts('PivotChart4SalesReport').



8. Using REST API we can get particular range of cell values,
now i wanna to get data from excel based on range of cell values

Cells range is B5 to E5

now the URL for getting the values is:

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Ranges('Sheet1!B5|E5')

and the output is:



9. Now i wannt to get complete table data, for this URL is:

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Ranges('Sheet1!B4|E9')

and OutPut is:


Till now we are used REST API for getting excel file data to show in browser.

Now i want to display charts in SharePoint.
9. Open your SharePoint site in browser. Add image viewer web part which is Available in "Media and Content" category.

Click on open the tool pane , it will open image viewer properties panel in that paste your REST API URL(which in Step 7.I).
And change Image viewer webpart Title and click on OK and save the page.

Note:
Like this you can add another chart in another Image view web part because default format for the chart is Image.

http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Charts('AllCitiesChart')
and 
http://demoshare:6969/_vti_bin/ExcelRest.aspx/SalesReports/SalesReport.xlsx/model/Charts('AllCitiesChart')?$format=image

both the URL are same.

Thats it..

pls let me know any queries or suggestions.

Will update more on excel service... very soon.