programming4us
programming4us
ENTERPRISE

SharePoint 2010 : Business Intelligence - Excel Services (part 2) - Accessing Excel Services Over SOAP

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/21/2011 11:46:32 AM

2. Accessing Excel Services Over SOAP

Just as you're able to access Excel sheets over REST based APIs, they are also exposed over SOAP based APIs. The previous sheet that I was working with involved a pivot table and pivot chart. Pivot tables and pivot charts are extremely powerful, but since their data is being driven by an external data source, they do not lend themselves to be changed easily from the front end.

For this section, let's craft up a slightly different and perhaps simpler Excel sheet. Let's say the sheet that I want to create reflects my daily activities for the day. This sheet can be seen in Figure 10.

Figure 10. An Excel sheet with various activities

If you note closely, C7 is filled with a formula, whereas the other rows in the C column are static values. Also, there is a pie chart being driven from the same data. Anytime I change the number of hours spent in any activity, the pie chart automatically redraws itself to show the updated data.

Publish this to Excel services and choose to also display this in the Excel web access WebPart. When choosing to display the sheet in the Excel web access WebPart, look for a check box called "All Workbook interactivity" under "General Interactivity Settings" when the webpart is in edit mode. Check that checkbox. The Excel sheet running in the browser looks like Figure 11.

Let's say that people are complaining that I was spending too much time drinking others. So, I need to reduce the time spent in biting and perhaps increase the time spent in eating. Go ahead and edit the Excel sheet, and change cell C6's value to eight. At the same time, click on cell C3 and change its value to four. You would note that the chart immediately reflects your changed values and also the formula at C7 immediately reflects your changed values in the browser. I wish my parents that easily reflected my changed values.

Figure 11. The Excel sheet running under Excel web access

There is one important thing to note here though. All the changes that you're doing from the Excel web access WebPart are being changed only for your current web session. In other words, if you were to close your browser and come back to the Excel web access WebPart, all the changes you had done previously would be lost. To make the changes permanent, you need to edit the source Excel sheet using thick client Excel or using Excel web applications.

Interestingly, all these embedded formulas and intelligence are a sheet that is exposed over a soap based API. Let's see this in action. Start Visual Studio 2010 and create a console application. In this console application, you will add a reference to /_vti_bin/excelservice.asmx, so this can be any version of .NET that can consume a web service. Since WCF can consume web services using basicHttpBinding, you're going to go with the .net 3.5 application. Call your console application ExcelSvcClient. In this console application, choose to add a service reference to http://sp2010/_vti_bin/ExcelService.asmx in the namespace ExcelService. After you have added the service reference, quickly examine the app.config for your client application. You should see a section that specifies the security settings for the client WCF application and you should change it to the following code:

<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>


This section now ensures that the client sends the NTLM identity to the server with all its requests. This is necessary since your SharePoint installation is protected behind active directory authentication.

Now modify the source code for your console application, as shown in Listing 1.

Example 1. Source Code for Your ExcelService As WCF client
private static string workbookURL = "http://sp2010/sheets/Book1.xlsx";
static void Main(string[] args)
{
ExcelService.ExcelServiceSoapClient client =
new ExcelService.ExcelServiceSoapClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel =
TokenImpersonationLevel.Impersonation;
ExcelService.Status[] outStatus;
string sessionID =
client.OpenWorkbook(workbookURL, "en-US", "en-US", out outStatus);
ExcelService.RangeCoordinates rc = new ExcelService.RangeCoordinates()
{
Column = 3,
Row = 6,
Height = 1,
Width = 1
};
client.SetCell(sessionID, "Sheet1", 4, 2, 10);
outStatus = client.Calculate(sessionID, "Sheet1", rc);
Console.WriteLine(
client.GetCell(
sessionID, "Sheet1", 6,2, false, out outStatus).ToString());
}


At this time, if you compile and run your console application, you would note that the total which is calculated out of a formula is written out to your console. Again, it is important to note that you interact with Excel services using the sessionID and these changes are specific only to your sessionID. The actual sheet itself is unchanged. You should further explore the various other methods available to you in ExcelService.asmx. Some of the interesting methods allow you to export binary data out of the sheet, or to export a snapshot of an edited sheet as a byte array.

Other  
  •  SharePoint 2010 : Business Intelligence - Visio Services
  •  Exchange Server 2010 : Perform Essential Database Management (part 3) - Manage Database Settings
  •  Exchange Server 2010 : Perform Essential Database Management (part 2) - Manage the Transaction Log Files
  •  Exchange Server 2010 : Perform Essential Database Management (part 1) - Manage the Database Files
  •  Architecting Applications for the Enterprise : UML Diagrams (part 3) - Sequence Diagrams
  •  Architecting Applications for the Enterprise : UML Diagrams (part 2) - Class Diagrams
  •  Architecting Applications for the Enterprise : UML Diagrams (part 1) - Use-Case Diagrams
  •  SharePoint 2010 : Creating and Managing Workflows - Monitoring Workflows
  •  Exchange Server 2010 : Administering Mailbox Content - Monitor and Restrict Communication (part 2) - Apply Common Monitoring and Restriction Scenarios
  •  Exchange Server 2010 : Administering Mailbox Content - Monitor and Restrict Communication (part 1) - Perform Basic Message Policy Configuration
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us