Cum Grano Salis

First "Hello World" code sample with the Excel Services APIs!

Welcome to the new world of Excel Services in the Microsoft Office Sharepoint Server 2007 product line! During the next few months, I will be exploring the various programmability capabilities of Excel Services.

 

On this first post of many, we will make our first “Hello World” application that uses Excel Services to execute Excel 2007 Workbooks on the server. I will be using Visual Studio 2005 throughout my samples, but any language or tool that supports consuming web services will be able to achieve the same results.

 

Note that for the most part, my examples will be in C# - I will try to include VB.NET samples for most of these posts though. I will post the VB.NET equivalent of the sample in this post next monday.

Preparing the workbook for the sample

To begin, we will need a workbook. This will be our Hello World workbook and will contain a single cell (A1 of course) that contains the following:

A1: Hello

A2: Excel 2003

A3: =Concatenate(A1, " ", A2)

 

After creating this workbook, save it to your favorite Sharepoint Library or UNC and make sure Excel Services is aware of that location in its Trusted Locations list.

Creating the form and importing Excel Services API

Next, we will create a sample Win-Forms applications that will contain a single text-box control and two buttons. We will set the text on one button as “Get Default” and call it getDefaultButton and set the text on the other to be “Get Correct” and set the name to be getCorrectButton.

 

Our sample application will get the value in A3 when the getDefaultButton is pressed. However, when the getCorrectButton is pressed, it will change the value in A2 to the correct version of Excel and get the recalculated value in A3 (which will hopefully be “Hello Excel 2007”).

 

The last part of the needed preparation is to import the Excel Services API into our Visual Studio 2005 project. To do that, we will go to the Project/Add Web Services menu option. In the dialog that opens up, in the address text box we will enter:

http://<sharepoint server name>/_vti_bin/ExcelService.asmx?wsdl

Also, in the Web Service Name we will enter “ES” – this will be our namespace for all things Excel Services API from now on.

Finally, writing code to get information from Excel Services

Next, we are going to implement the code behind the Get Default button. The first step is to actually create the proxy object. We will place that object inside a using() statement since it implements the IDisposable pattern (note that neither the generated proxy class nor any of the classes it derives from actually do any real work in their dispose, but since the base class Component has a Finalizer, we will incur some unneeded perf degredation if we don’t dispose):

 

using (ES.ExcelService excelService = new ES.ExcelService())

{

       excelService.Credentials = System.Net.CredentialCache.DefaultCredentials;

}

 

So far so good – we created the proxy instance. This instance will allow us to actually make calls into Excel Services. Note that we set the credentials to be those of the user that is currently logged on to the machine – if we don’t do that, there’s a good chance the web server will deny us access to the web-service.

 

Next we will call into the server, requesting that it opens the workbook we saved. We will do that by calling into the OpenWorkbook() method. This method will try to open the workbook on the server – if it succeeds, it will return a session id that we will use to continue the communication with the server. The other parameters this method takes are the locales to use (I am leaving these empty for now – more on those at a later blog) and an out parameter that will contain status information on the operation (more on that in a later post as well):

 

using (ES.ExcelService excelService = new ES.ExcelService())

{

       excelService.Credentials = System.Net.CredentialCache.DefaultCredentials;

       ES.Status[] stati;

       string sessionId = excelService.OpenWorkbook(

              "http://MyServerName/Shared Documents/HelloWorld.xlsx",

              String.Empty, String.Empty, out stati);

}

 

If our call did not fail, it means we have a workbook waiting for us on the server. Next, we will get the value from cell A3 (the one that contains the formula). For that, we will add the following code below the OpenWorkbook() call:

 

       object o = excelService.GetCellA1(sessionId,

              "Sheet1",

              "A3",

              true,

              out stati);

 

As you can see, we pass the session id we got from the OpenWorkbook() call into the GetCellA1() call (the A1 in the name of the method denotes the way the method works – it can be used to get any cell from the workbook) – almost all the methods on the Excel web service require this first parameter. The second and third parameters are used to tell Excel Services what part of the workbook we want. In this case, we want cell A3 in Sheet1. The Boolean we pass as the fourth parameter tells Excel Services if we want the data returning to be formatted or not . The last parameter is the status array.  More on those parameters and on the various ways to get data from Excel Services in a future post.

 

The local variable o should now hold the string “Hello Excel 2003”.  There are two more things we need to do before we finish with this phase. The first is to place the value we got from the cell into the text box and the other is to close the workbook we opened. Note that Excel Services will timeout workbooks that are left opened on the server. To minimize wasted resources, it is advised that you close a workbook you are done with. So the final code will look like this:

 

using (ES.ExcelService excelService = new ES.ExcelService())

{

       excelService.Credentials = System.Net.CredentialCache.DefaultCredentials;

       ES.Status[] stati;

       string sessionId = excelService.OpenWorkbook(

              "http://MyServerName/Shared Documents/HelloWorld.xlsx",

              String.Empty, String.Empty, out stati);

 

       object o = excelService.GetCellA1(sessionId,

              "Sheet1",

              "A3",

              true,

              out stati);

 

       textBox1.Text = (string)o;

 

       excelService.CloseWorkbook(sessionId);

}

 

If you run your program now and click the Get Default button, you should get the “Hello Excel 2003” appear in the textbox.

Writing data back to Excel Services

We will now add code to the other button. Feel free to copy and paste the code we wrote for the first one into the Click event of the second one – we will just be adding code.

 

For this second example, we will write the value “Excel 2007” into the A2 cell – if everything works right, and you get the value from A3 (after setting the value in A2 of course), you should see the text “Hello Excel 2007” in the cell, instead of the default one in the saved workbook. For that, we will add a call to SetCellA1()  into the code we copied from the Get Default button, right before we call GetCellA1():

 

excelService.SetCellA1(sessionId, "Sheet1",

       "A2", "Excel 2007");

 

That’s it! If you now run your sample and click the “Get Correct” button, you should see “Hello Excel 2007” in the textbox!

So what did we learn?

  • We now know how to add a web reference to Excel Services so that we can use it in our program.
  • We used the OpenWorkbook() method to open a workbook on the server.
  • Calling the SetCellA1() method allows us to manipulate the workbook that’s opened inside the session OpenWorkbook() gave us.
  • To get data from the workbook, we can call the GetCellA1() method.
  • When we are done with our session, we can call the CloseWorkbook() method.

 Note about the attached sample: You will need to change the name of the workbook constant at the top of the Form1 class to work with the name of your workbook. You will also need to change the ES web service properties to point to the server that hosts your Excel Services.

Published Friday, March 24, 2006 9:03 PM by Shahar
Attachment(s): Blog_HelloWorld.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Microsoft Excel 2007 (nee Excel 12) said:

For those of you interested in programming Excel Services, check out this blog.
One of the developers...
March 28, 2006 2:44 AM
 

Paolo said:

Thank you for this nice code preview.
(Just a linguistic note: the plural of Latin word "status" is "status" (4th declension, not 2nd declension) ;-).
March 29, 2006 7:10 PM
 

Shahar said:

But it's not as funny. :)
March 30, 2006 8:08 PM
 

Cum Grano Salis said:

Excel Services does not support External Workbook References. I show how you can use a UDF to get similar functionality.
May 2, 2006 2:18 PM
 

Blog de P@blo - [MVP - Windows Server Customer Experience] said:

Durante la preparaci&#243;n de las sesiones para el evento DevDays Andino 2006, cuyos temas principales fueron...
May 30, 2006 4:19 PM
 

Prasad said:

I copied the assemblies Microsoft.Office.Excel.Server.WebServices and Microsoft.SharePoint to my pc from the maching where Office Server is installed.I added the references to these in my console application.But at runtime it throws an error at the line where i am instantiating the ExcelService class saying that it could not load the assembly Microsoft.Office.Excel.Server.Is there any assembly by this name?
June 7, 2006 12:00 AM
 

Shahar said:

Prasad:

Read the part in the article about "Creating the form and importing Excel Services API". You dont need to copy these assemblies - just use VS to create a proxy to the web-services.
June 7, 2006 2:46 AM
 

Prasad said:

Hi Shahar

I have added the Web Refernece of the ExcelService web service in my console application.However I dont find any class by the name ExcelService in the instantiated proxy class.Instead I find the class ExcelServiceSoap.Although this contains a method called OpenWorkBook,the signature of the method is entirely different from what is given above eg and also in the msdn example which corresponds to the ExcelService class in the assembly Microsoft.Office.Excel.Server.WebServices.
June 7, 2006 4:38 AM
 

Prasad said:

Moreover I am using Office Server 2007 Beta 2.
June 7, 2006 4:38 AM
 

Prasad said:

Thanks!
I realized my mistake.I had put the reference of the ExcelCalculation Server/ExcelService.asmx in my console application.
June 7, 2006 4:46 AM
 

benjaminm's blog said:

June 12, 2006 12:47 PM
 

KieuAnh said:

I need comment code
August 21, 2006 12:07 AM
 

Shahar said:

KieuAnh:

Not sure what it is you want. Can you elaborate?
August 21, 2006 6:28 PM
 

DotNetInterop said:

A related post - this one shows a Java application connecting with Excel Services via the web service interface.  -Dino
September 7, 2006 12:38 PM
 

Martin Parry said:

This post is a list of useful resources for developers working with the 2007 Microsoft Office&amp;nbsp;System...
September 13, 2006 9:11 AM
 

Tyler said:

Shahar,

Can you comment if the CalculateA1 function is working.  I have a namedrange cell with a Rand() function in it.  When I open the workbook and try to CalculateA1 the cell with the rand() function it doesnt seem to update.  Any ideas?   I am not running the tech refresh.
September 15, 2006 8:17 PM
 

Shahar said:

Tyler,

The reason you are not seeing anything change is that Excel Services optimizes the recalculation - it will not let a user recalc more than once per 5 minutes. This is configurable inside the Trusted Location - there's a setting called "Volatile function lifetime" or something similar that you can use to adjust the 5min. Setting it to zero will make it so that every recalc will realy recalc. Note that reducing this setting will impact performance as it will require Excel Services to recalculate more often.

In B2TR, there's a slight change (as far as I remember) - a manual recalc will ignore the volatile cache time and actually do a recalc.
September 16, 2006 4:34 AM
 

LuisBE on Services said:

Instead of re-hashing information I've found elsewhere I figured a pre-reqs post would be good.
One...
September 29, 2006 1:45 AM
 

LuisBE on Services said:

Instead of re-hashing information I've found elsewhere I figured a pre-reqs post would be good. One of

October 30, 2006 8:50 PM
 

Rohit said:

A very neatly explained example.

Great work!!!

November 15, 2006 5:45 AM
 

Amarnath reddy said:

Hi,

I have tryied this example.Iam able to gat the data from the excel but unable to write the data into the excel by using  "SetCellA1" property.

anyone can help on this.

Thanks&Regards,

Amar...

November 16, 2006 3:16 AM
 

Shahar said:

What error are you getting? Can you share the code you are running?

November 16, 2006 3:22 AM
 

Amarnath reddy said:

Hi Shahar,

Iam not getting any error.i folowed the same steps which u have given.

this is the code which iam writing data into the excel which is in Sharepoint server 2007 using excel webservices.

Code:

---------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Try

           Dim mystat() As MyExcelWebReference.Status

           Dim targetpath As String

         Using es As New MyExcelWebReference.ExcelService()

            targetpath = "http://SharepointServer/ExcelServices/Amar/Shared%20Documents/Amar.xlsx"

               es.PreAuthenticate = True

               es.Credentials = System.Net.CredentialCache.DefaultCredentials

               sessionid = es.OpenWorkbook(targetpath, String.Empty, String.Empty, status)

               If (sessionid = "") Then

                   MsgBox("Error in Opening Workbook")

               Else                                    

                   es.SetCellA1(sessionid, "Sheet1", "A1", "Amar")

               End If

               es.CloseWorkbook(sessionid)

            End Using

       Catch ex As Exception

           MsgBox(ex.Message)

       End Try

   End Sub

---------

End Code

Please look into this and give me the code sample.

Thanks&Regards,

Amar...

November 16, 2006 3:41 AM
 

Shahar said:

Oh.

Are you expecting to see the value change inside the Excel workbook inside sharepoint?

November 16, 2006 4:01 AM
 

Amarnath Reddy said:

Hi Shahar,

Thanks for the fast response...

yes i want to write some data into the excel located in the share point server 2007.

can you give me the points.

Thanks&Regards,

Amar....

November 16, 2006 4:39 AM
 

Shahar said:

Ezcel Services is not an authoring environment. It was not meant in this version to "Save Back" to the SP server.

It's still possible, but requires a few more steps.

1. Call the GetWorkbook() method on the proxy to get back a byte array represnting your workbook.

2. Use the SharePoint OM to save that byte array back to the server.

November 16, 2006 4:56 AM
 

Amarnath reddy said:

Thanks Shahar,

please can you give me the sample code steps for this.

once again thanks for the response.

Regards,

Amar...

November 16, 2006 5:06 AM
 

Shahar said:

I can, but it may actually take me a little while to do this. Don't have time for posting articles right now and while it's not complex, it's a fair amount of code.

Until I get to do it, I suggest you search for information on how to use the SPFile.SaveBinary() method and take a look at the GetWorkbook() method of Excel Services.

s

November 16, 2006 5:26 AM
 

AmarnathReddy said:

Thanks for the info..

I will check the details...

Regards,

Amar...

November 16, 2006 5:34 AM
 

Amarnath Reddy said:

Hi All,

I need some syntax to know the Active excelsheet name which i have opened using excel webservices.

please give me the code samples for that.

i want to see the active sheet neme when i open the excel in "view in browser" option in sharepoint server.

November 17, 2006 1:21 AM
 

Shahar said:

Can you elaborate on "i  want to see the active sheet neme when i open the excel in "view in browser" option in sharepoint server"?

Not sure I undestand what you mean.

s

November 17, 2006 1:29 AM
 

Amarnath Reddy said:

Hi Shahar,

I have published my excel sheet into the sharepoint server 2007.

in that sheet in one cell i have placed one formula(i.e udf function) to get the activesheet name.

now when i want to go and see the excel in "view in browser" option in Sharepoint server 2007t then i want to get the active sheet name in the given cell whare i have given the formaula.

please help me out on this.

Regards,

Amar...

November 17, 2006 1:42 AM
 

Shahar said:

What is the UDF that returns the ActiveSheet name exactly? I wasn't aware that we supported something like that.

(Which, of course, does not mean much, since there are many Excel functions I am not aware of. :))

s

November 17, 2006 2:01 AM
 

Amarnath Reddy said:

Hi Shahar,

I need one excel inbuilt funtion to get the Activesheet name.

that only i want to write in the UDF to get the Active sheet name.

Regards,

Amar..

November 17, 2006 2:05 AM
 

Shahar said:

There is no such feature.

November 17, 2006 2:29 AM
 

Shahar said:

Can you explain what you need it for? It may help us in a future release.

November 17, 2006 2:33 AM
 

Amarnath Reddy said:

Hi Shahar,

Thanks...

Regards,

Amar...

November 17, 2006 2:34 AM
 

Anirudh said:

Hi,

I used the information in this blog to work with the excel services API within MOSS 2007 and was able to do a variety of activities with the exposed web service.

I am trying to access the same web service from a RTM Project Server website. The website exposes the particular webservice but I cannot add the reference itself. The Add Reference button is disabled and I get the following error messages:

<<

The document at the url http://litware:104/_vti_bin/ExcelService.asmx?wsdl was not recognized as a known document type.

The error message from each known type may help you fix the problem:

- Report from 'DISCO Document' is 'Root element is missing.'.

- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'.

- Root element is missing.

- Report from 'XML Schema' is 'Root element is missing.'.

>>

Is this an issue specific to Project Server RTM?

I then tried to access the excelservice webservice(the wsdl) of a RTM MOSS 2007 website and got the following error:

<<

Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.IVsExtensibility'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3C536122-57B1-46DE-AB34-ACC524140093}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

>>

When I tried to add this webservice it allowed me but w/o the wsdl document.

I've never faced such problems with the Beta2 versions of MOSS.

I haven't found any info on these issues elsewhere and so any help would be appreciated.

January 29, 2007 4:45 AM
 

Vandana said:

How does a workflow work in Excel services?Basically i would like to know how the excel workbooks published on to the server behave when a workflow is  started.Will the documents be visible to particular user only after it is approved by the initiatir or some other approver?

Thanks,

Vandana

January 29, 2007 7:41 AM
 

Shahar said:

Anirudh:

As for the first question: Excel Services is only enabled on the Enterprise version of MOSS. As far as I know, Project server is a different SKU that does not support it.

For more help on that, you can try accessing the forums: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1208&SiteID=1

As for the second question: What is it that you are doing exactly when you say "I then tried to access the excelservice webservice of a RTM MOSS 2007 website"? Where do you get that COM error you describe?

January 29, 2007 11:26 AM
 

Shahar said:

Vandana:

It all depends on what workflow you apply to the document library in question. There is no inherent process that happens for Workbooks on the server.

January 29, 2007 11:28 AM
 

Vandana said:

Hi,

Thanks for the reply.I need bit more clarification on workflows.

I have used approval workflow which routes the documenst thru all the workflow participants.

whai i feel is once a document is approved then only it should go to next level for further processing.

but i find no such restriction in excel services.Is there any  locking mechanism either thru custom workfkows or with predefined workflows wherein a workbook is viewed only if it approved by a particular user?

Thanks,

Vandana

January 30, 2007 1:12 AM
 

Anirudh said:

Hi Shahar,

First off thanks for the prompt reply!

:)

Well its a disappointment if exceservices is not supported for project server, because even the project web access websites created under Project Server offer that excelservice webservice,i.e. you can see it when you try to add the web reference.

However it doesn't let you add this reference(button disabled) and the errors are printed in the web service despcrription txtbox.

>>

The document at the url http://litware:104/_vti_bin/ExcelService.asmx?wsdl was not recognized as a known document type.

The error message from each known type may help you fix the problem:

- Report from 'DISCO Document' is 'Root element is missing.'.

- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'.

- Root element is missing.

- Report from 'XML Schema' is 'Root element is missing.'.

<<

After that I tried to access a webservice of a MOSS RTM site (on the same machine) and got the COM error.I got a workaround for that(it was a site specific error)

That was not the main issue; I really needed the excelserviceAPI for Project server. Are you sure it is not supported?

:(

January 30, 2007 2:31 AM
 

Shahar said:

Anirudh,

I am double-checking. But I think Excel Services comes only as part of the enterprise version.

Vandana,

I sent an email in the internal alias to see if something comes up.

Both:

Consider using the Excel Services forums (http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1208&SiteID=1) for questions such as this - you will get more eyes on them.

January 30, 2007 1:13 PM
 

Shahar said:

Anirudh,

Excel Services only comes as part of the MOSS for Internet Sites or the Enterprise packages. For more info, please follow this link:

http://office.microsoft.com/en-us/help/HA101978031033.aspx

January 30, 2007 1:23 PM
 

Amarnath Reddy said:

Hi All,

I have created a approval workflow and i have added approvers name as administrator,spuser1 and i have assighned the work flow to the test document.after that i have loged in to the sharepoint server as another user.when i want to open the test document without approving the document logedin user able to open and edit the document but it should display some type of message like "it is not yet approved by the administrator workflow is in process".

is there any locking is available for the document when workflow is processing.

please anybody can give the flow of the work flow and approval steps and workflow conifiguration.

regards,

Amar...

February 1, 2007 12:11 AM
 

Amarnath Reddy said:

Hi All,

I want to know how to auto schdule my excel files in sharepoint server 2007.is there any provision given by sharepoint server 2007 to schdule the files and also programatically how can set the schduler.In sharepoint there is one dll i.e Microsoft.SharePoint.SPSchedule

how can we work on this iam not clear.can anybody can send sample code and help on this.

Thanks&Regards,

Amar..

March 21, 2007 1:50 AM
 

Shahar said:

Can you explain what "Auto Scheduling" means? What's the expected behavior? What do you want them to auto schecule to?

March 21, 2007 7:02 AM
 

Sasya said:

Hi Sahar,

While opening the workbook I am getting "The file that you selected could not be found. Check the spelling of the file name and verify that the location is correct" error, but the path of the excel that I am giving is correct. How can I resolve this.

Can we refresh the document that is stored in Sharepoint under Excel trusted Location by calling Refresh method that is available with Excel services workbook? Is this possible?

May 11, 2007 1:15 AM
 

Sasya said:

I am getting the Error while opening the workbook, error is "You do not have permissions to open this file on Excel Services." The excel file that I am opening is in trusted location in sharepoint. Do we need to give any permissions to that document in sharepoint document library.

How do I can resolve this?

Here is the full code

      ExcelService currentService = new ExcelService();

       string targetPath = "http://localhost/Documents/TestDoc.xlsx";            

       Status[] outStatus;

       currentService.Credentials = System.Net.CredentialCache.DefaultCredentials;

       string sessionId = currentService.OpenWorkbook(targetPath, "en-US", "en-US", out outStatus);

Thanks in Advance,

Sasya

May 11, 2007 11:19 AM
 

Shahar said:

Can you choose "View in WebBrowser" in the drop down on the file?

May 13, 2007 10:53 AM
 

Sasya said:

View in WebBrowser" in the drop down on the file is working from Sharepoint document library.

But I am getting the error while accessing using Excel web services.

How do I resolve this error?

Thanks,

Sasya

May 13, 2007 11:52 PM
 

Sasya said:

The excel sheet that I am trying to access from Excel Service also has Data Connections, which are used to pull data from database(SQL server).

Thanks

Sasya

May 14, 2007 12:31 AM
 

Sasya said:

Hi,

I am using Excel services for refreshing the excel sheet and then trying to save refreshed document to the Sharepoint library.Below is the thing that I am trying out:

1. Opening the workbook from Sharepoint trusted location.

2. Refreshing the excel report(Has Pivot Tables and Pivot Charts).

3. Writing refreshed data to an external file.

Here is the code:

       ExcelService currentService = new ExcelService();

       string targetPath = "http://localhost/Documents/EmpDept.xlsx";

       Status[] outStatus;

       currentService.Credentials = System.Net.CredentialCache.DefaultCredentials;

        string sessionId = currentService.OpenWorkbook(targetPath, "en-US", "en-US", out outStatus);

       currentService.Refresh(sessionId, "Employees");

       byte[] contents = currentService.GetWorkbook(sessionId, WorkbookType.FullWorkbook, out outStatus);

using (BinaryWriter binWriter =

       new BinaryWriter(File.Open(@"C:\Test.xlsx", FileMode.Create)))

       {

           binWriter.Write(contents);

       }

       currentService.CloseWorkbook(sessionId);

I have modified my data source by adding new records,

But even after the refresh also the excel report is not getting refreshed. When I check Text.xls it is as same as the Source excel and not updated with the latest data from data source.

When I refreh the Connection from Excel the sheet is getting refreshed with the latest data from my datasource.

Is there anything I am missing here?

Any help will be appreciated.

Regards,

Sasya

May 14, 2007 3:12 AM
 

Shahar said:

Sasya:

RE: Failure of EWA

What's the error you are saying?

RE: Api question.

Hmm. That's very strange.

1. What does the connection shunt information to? (PivotTable?)

2. What happens if you call .RefreshAll() instead of .Refresh()?

s

May 14, 2007 3:39 AM
 

Sasya said:

Thanks for the response,

ConnectionString Info:

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=SolutionMetaData;Data Source=xxxx;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=Test;Use Encryption for Data=False;Tag with column collation when possible=False

CommandType:Table

CommandText:DataBase.TableName(Sample.Employees)

From C# Code for Excel Services:

If I call .Refresh by passing in second parameter as empty then it will refresh all the connections(Source:MSDN) I have tried the one below, but still it doesn't refresh.

currentService.Refresh(sessionId, "");

If I am refreshing the report from Excel client by using Refresh or RefreshAll from Connections Tab I am able to see the updated report in excel. But which is not happening from Excel web services.

Thanks,

Sasya

May 14, 2007 6:25 AM
 

SL said:

I have a problem opening a workbook from a remote machine using Excel web services.

I am getting the following error:

URL authorization failed for the request

I am using the default credentials for Excel web services in code.

from X machine I am calling openworkbok for the url on machine MySite

URL passed in as parameter for OpenWorkBook is :http://MySite/Reports/Salaries.xlsx

Thanks in advance

SL

May 14, 2007 9:59 AM
 

Shahar said:

May 14, 2007 10:01 AM
 

SL said:

If I try to access the url http://MySite/_vti_bin/ExcelServices.asmx I am getting the error from machine x as well as machine Mysite, and Just it is displaying that an Error has occurred.

In eventViewer I didnt see any message related to that.

But on Mysite I can view http://MySite/Reports/Salaries.xlsx without any error in WebBrowser by clicking View in WebBrowser link in the dropdown in Document library.

But If I am accessing ExcelServices.asmx on MySite machine with http://localhost/_vti_bin/ExcelServices.asmx, I am able to access it without any error.

And in IIS for Office Server Web Services is configured with both Annonymous and Windows authentication.

MySite/_vti_bin/ExcelServices.asmx is also configured with both Annonymous and Windows authentication.

Thanks,

SL

May 14, 2007 10:45 AM
 

Sasya said:

Sahara,

        I have strucked with the Data refresh problem using Excel services using C# code. It is not working as documented in MSDN if my document has data connections to external data sources.

Thanks in Advance,

Sasya

May 14, 2007 11:16 AM
 

Shahar said:

Sasya,

If you choose the "Refresh All Connections" from the  EWA toolbar does it work?

(So, load the file in EWA and select the "Refresh ALL" and see if you get the new information you expect).

May 14, 2007 11:22 AM
 

Ira Levin said:

SL,

Excel Services API isn't accessible to anonymuos users, so you either must authenticate by supplying a network credentials (e.g. CredentialsCache.DefaultCredentials), or if you'd like you can modify the permissions of the anonymous user so that it has the "UseRemoteApi" permission. You can alter the permissions of the anonymous user from OM, or you can grant anonymous users full access to websites.

I hope this helps.

May 14, 2007 12:04 PM
 

SL said:

Hi Levin,

Here is the code that I am using:

ExcelService currentService = new ExcelService();

       string targetPath = "http://MySite/Reports/Salaries.xlsx";

       Status[] outStatus;

       currentService.Credentials = System.Net.CredentialCache.DefaultCredentials;

       string sessionId = currentService.OpenWorkbook(targetPath, "en-US", "en-US", out outStatus);

       currentService.Refresh(sessionId, "");

       byte[] contents = currentService.GetWorkbook(sessionId, WorkbookType.FullWorkbook, out outStatus);

In my code I am using CredentialsCache.DefaultCredentials, but still OpenWorkBook is throwing out an error. And annonymous access in IIS is configured with Service account.

And I have tried running this code from the machine MySite, I am still getting the error.

Regards,

SL

May 15, 2007 12:05 AM
 

Majeti said:

Hi Anirudh,

if you have created a site collection then use the url reference as:

http://<server>/sites/<sitename>/_vti_bin/excelservice.asmx

Regards

Majeti

May 23, 2007 10:56 AM
 

Sush said:

Hi All,

I have deployed a web application which uses excel web service on a sharepoint site. I have some named items on the excel sheet. How can i programatically get the list of all the named items/parameters defined in there.

Regards,

Sush

July 6, 2007 6:36 AM
 

Shahar said:

You cannot. The only workarounds you have available (afaik) are:

1. Know the names before hand.

2. Place the names in a hidden sheet and have a well known range name for the range that contains all the named ranges. Then use that to get the names.

July 9, 2007 1:09 PM
 

Frank van de Groep said:

Hi there,

My project/app is called Webexcel1. I added a webreference called ES. But it doesn't recognize the namespace ES.

I tried it with the first using and the second one.

...

//using Webexcel1.ES;

using System.Web.Services.Protocols;

using (ES.ExcelService excelService = new ES.ExcelService())

{

      excelService.Credentials = System.Net.CredentialCache.DefaultCredentials;

}

...

Thanks!

Frank

July 26, 2007 8:03 AM
 

frankjnf said:

Already solved my problem. It was due to a lack of knowledge in VS. I had the using declarations in the wrong spot of my project. Basics....

Works fine now.

Thanks and good luck.

July 28, 2007 7:19 AM
 

Sachin Vyas said:

Thanks for nice article.

But i am getting an Soap Exception error "An error has occured" message. in foolowing line

string test = es.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);

can anyone help me why i am getting this exception and how i can solved it.

Thanks in advance.

September 27, 2007 9:23 AM
 

thana said:

hi!

my servlet return excel file i am getting excel file for java script request,but let me know how do open or display excel file through ajax responseText

regards

Thana

September 28, 2007 2:08 AM
 

Shahar said:

That's not something you can do today.

The only thing you can do is use AJAX to get data from Excel Services.

October 1, 2007 6:45 PM
 

VVS said:

is it necessary to install office 2007 and devloper's machine or they can access from share point server. if Office 2003 is present on the local system

what are the minimum requirements for developer machine

if share point server machine has share point 2007 and excel 2007

November 23, 2007 3:13 AM
 

Shahar said:

You dont need anything installed on the Developer machine - just a connection to the Excel Services SharePoint.

November 28, 2007 6:37 PM
 

Jason said:

I'm running into a soap exception error that a few of you mentioned previously. I get a "You do not have permissions to open this file on Excel Servcies" error when on the line of code where the ExcelService.OpenWorkbook function is called. I'm passing into the function the default credentials and a valid location. I've added the location of the xlsx workbook as a trusted WSS file location but i still get this error. I'd like to know if there are any possible explanations for this error. Thanks in advance guys.

February 22, 2008 2:04 PM
 

Shahar said:

Can you open the file via EWA?

When you run into issues like that, that's the first thing you should check - that will tell you whether the issue is with the server or with your software.

February 22, 2008 2:21 PM
 

Jason said:

I can open it via EWA. Sorry bout leaving that part out before. I'm thinking it might have something to do with either the default credentials I'm passing into the function. Or that it has to do with the workbook location. The workbook is located in a content database path (http://servername/site/subsite/filename.xlsx).

February 22, 2008 2:58 PM
 

Phaneendra said:

Can i set security on Sheet level in a published workbook in Excel Services? My intension to publish a workbook with four sheets( i.e. user1,user2,user3,Admin). Every user have only access to his/her sheet only.

But Admin can view all sheets as well as by using excel built-in formulas he can go for some calculations by taking input from some/all other user sheets information.

Does it possible in Excel Services?

February 25, 2008 6:37 AM
 

Shahar said:

Jason:

If your user can open it in a browser, they should be able to open it through the API. What type of application is this?

Phaneendra:

We do not support this level of granularity with security - sorry.

February 26, 2008 8:12 PM
 

Anshuman said:

I am facing a similar kind of issue regarding SOAP exception at OpenWorkBook method.

i am able to open the sheet in browser, i.e. it is working fine in EWA, but  not coming up using web service.

I have checked that the workbook is stored at the trusted location. also I have checked the permission of the user. It's not working even by providing the Full Control.

What else could be the possible reason for this SOAP Exception?

February 28, 2008 2:28 AM
 

Shahar said:

Can you paste the skeleton of your code (everything relevant up to and including the OpenWorkbook call)?

February 28, 2008 1:06 PM
 

Anshuman said:

Here is that snippet of code:

private void button1_Click(object sender, EventArgs e)

       {

           ExcelService proxyService = new ExcelService();

           proxyService.SoapVersion = SoapProtocolVersion.Soap12;

           proxyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

           Status[] status = null;

           string SessionId = null;

           string pathWorkbook = "http://litwaredemo:13300/sites/mysitecollection/ExcelWorkBooks/Calculator.xlsx";

           SessionId = proxyService.OpenWorkbook(pathWorkbook, String.Empty, String.Empty, out status);

           status = proxyService.SetCellA1(SessionId, "Calculator", "Loan", textBox1.Text);

           status = proxyService.SetCellA1(SessionId, "Calculator", "Rate", textBox2.Text);

           status = proxyService.SetCellA1(SessionId, "Calculator", "Years", textBox3.Text);

           status = proxyService.CalculateWorkbook(SessionId, CalculateType.CalculateFull);

           object result = null;

           result = proxyService.GetCellA1(SessionId, "Calculator", "Payment", true, out status);

           if (result != null)

               textBox4.Text = result.ToString();

           proxyService.CloseWorkbook(SessionId);

       }

Its just a small application for calculation.

SessionId = proxyService.OpenWorkbook(pathWorkbook, String.Empty, String.Empty, out status);

this line of code is throwing the SOAP exception.

February 29, 2008 2:29 AM
 

Satish said:

hey guys i have s problem........

While using UDF's i get the return values in a data table.

Now i wannt to show this entire table in the excle sheet as it is.

How can I do that?

March 13, 2008 1:55 AM
 

Shahar said:

Can you further explain what the issue is?

what do you mean by Data table? What tdo you mean "as it is"?

March 13, 2008 2:24 PM
 

Sanjay said:

Hi,

The OpenWorkbook() is throwing the following exception:

"Excel Web Services could not determine the Windows SharePoint Services site context of the calling process"

Please note:

1> I'm using Excel Web Reference not static binding

2> The excel file is in trusted location.

3> I'm able to browse the excel file using IE.

Please let me know what colud be the problem?

March 26, 2008 9:29 AM
 

Kiran Reddy said:

Hi Sahar,

This is kiran reddy. i Want to know how to convert  excel data in Visual Basic code language

August 17, 2009 10:47 AM
 

Shahar said:

Not sure I understand the question, Kiran.

August 17, 2009 2:55 PM
 

kiran reddy said:

how to learn visual basic through online? is there anybody to teach VB

August 18, 2009 10:08 AM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker