Thursday, December 31, 2009

What is new in Excel Service in SharePoint 2010??

Excel Services was one of the features that was widely used by large organisations with MOSS 2007. It was used to render the content of Excel worksheet in Internet Explorer so that you can only one true copy of the worksheet rather than everyone carrying there own copy and modifying it.
Also at the same time we also had Excel Web Access Web Part which could be used to publish the excel sheet anywhere in the site.

With SharePoint Server 2010 the Excel Services Team went one step ahead. They introduced a new API called REST API (REpresentational STate).

REST API is a easy programming feature for "non-developers" to easily access and display the information present in the excel worksheet. You may be confused with the above sentence as it contains the words programming and non developers. What I mean by the sentence is REST API feature can be achieved by just going manipulation to the URL which can be done by a non-developer (like me).At the same time it gives developers a platform on which they can do very complex operations as well.

Now lets talk where and how can we use the Excel Services with REST API:

For Example : Say you create a worksheet and that worksheet has the number of hours that you have worked for the entire week. Something similar to the below image




Now lets say you and your team have a requirement from your manager to show a graph of the work done in the entire week.
So you create an interal site and you would like to embed the above "chart/graph" in that site. You have to first publish the particular excelsheet to the a document library (lets consider we have a document library
called Worksheet library and the excel sheet is publish to this using excel services.The procedure to publish the excel sheet using excel services remains the same as in MOSS 2007).

Once the above is done, using the REST API by writing the following URL in the address of the  image web part in SharePoint Server 2010 you will get the chart/graph. (for time being ignore what exactly does the URL mean and do).

http://teamsite/sites/manager/_vti_bin/ExcelRest.aspx/worksheetlibrary/Book1.xlsx/Model/Charts('WorkChart')

Hurry!!!!..... Thats the end result of REST API. You have the chart in the site.!!!.....

The data shown the graph is NOT static, its dynamic. That means when whenever the value chages the graph gets automatically updated in the site.With the REST API, any changes in the workbook are reflected in the data that is returned. This includes the latest edits made to the workbook, functions that have recalculated (including User Defined Functions), and external data that is refreshed.

The REST API can also push values into the workbook, recalculate based on those changes, and return the range or chart you requested after the effects of the change have been calculated. For example, in the sample spreadsheet above, the chart is displaying the effects of a Actual Work done = 80% .With REST, you can request a chart displaying the effects of a Actual work done = 70% by adding a parameter to the URI that changes the value of cell B4 to 70%.
Now we know what the end result is and how to achieve using. Next lets have a discussion on how we came to that particular URI.

Firstly I have a site collection built and named as "teamsite". In that team site I have created another site and named it as "manager" and in the manager site I also have a document library called "worksheetlibrary" to which I have published my excel sheet.
So to access the excel sheet i would type the URI as http://teamsite/sites/manager/worksheetlibrary/Book1.xlsx (assumption that the excel sheet is saved as Book1.xlsx)

Now in order to use the REST API in the URI we insert _vti_bin/ExcelRest.aspx just before the document library in the above URI.Hence the URI would look like

http://teamsite/sites/manager/_vit_bin/ExcelRest.aspx/worksheetlibrary/Book1.xlsx

Now we need to get to the items in thee excel sheet like the chart or the table. For that we add /Model at the end of the URI. So now the URI is

http://teamsite/sites/manager/_vti_bin/ExcelRest.aspx/worksheetlibrary/Book1.xlsx/Model

Once you add "/Model" to the URI and hit enter you will find 4 terms listed in the Internet Explorer page. They are:

1.Ranges.
2.Charts.
3.Tables.
4.PivotTables

Important
-----------
Before proceeding further you need to make sure that the chart and/or the table in the excel are named ranges. Basically you need to select the chart and give it a name and if you also interested in publishing the table with the Hours Worked and Billed Time data then select the entire table and give it a name.(Giving the name is simple,just select the table and left top corner above the cell 'A' type the name that you would like to give.) THIS HAS TO BE DONE BEFORE PUBLISHING THE EXCEL TO THE DOCUMENT LIBRARY.

Next at the end of the URI type /Ranges and you will be given the list of named ranges that you have defined in the excel sheet.

Lastly you need to choose which range you would like to publish. In out case since its a chart the URI will become

http://teamsite/sites/manager/_vti_bin/ExcelRest.aspx/worksheetlibrary/Book1.xlsx/Model/Charts('ChartofHours')?$format=html

(ChartofHours is the name for the chart that I defined)

or you just also just type

http://teamsite/sites/manager/_vti_bin/ExcelRest.aspx/worksheetlibrary/Book1.xlsx/Model/Charts('ChartofHours')

Once the chart is displayed in the IE page copy the URI, go the SharePoint site,edit the page,click on image in the ribbon menu, you will be given two options,choose "from address", put-in the URI and its done.

Now whenever you can values in the excel sheet that chart also gets updated in the site.

For more information on Excel Services refer the following links:
1.Excel Services - Rest API Part 1
2.Excel Services - Rest API Part 2

2 comments:

  1. I like to work with Excel files, because of I have something like this an insurance from various accidents. I acquired this application on a soft blog. To my good fortune this software helped me rapidly and above it may help for distinct complicated propositions as well - Excel files fix.

    ReplyDelete
  2. Hello
    Nice Post
    I have tried and could not open the excel itself through url

    ReplyDelete