Today's author, Sanjay Kulkarni, a Program Manager on the Excel Services team. We have heard from several customers about scenarios where they have workbook dependencies. So the output of one workbook is used in other workbooks for calculations. The dependencies could be a result of the business model meaning different people in the organization being responsible for the workbooks or it could simply be a way of isolating related logic in different workbooks. In this blog post we will look at a sample way of how these workbook dependencies can be handled by writing a little code using Excel Services Web Services API and SharePoint object model. Note that you will need MOSS 2007 with Excel Services configured to use what is described here. To simplify things let us look at a scenario with two workbooks. At a high level workbook one (Rates.xlsx) has mortgage rates that are refreshed from the database. This workbook also adds the overhead and calculates the retail rate that can be offered to customers. The second workbook (Payments.xlsx) has a list of potential customers and information about them. The idea is to calculate the first workbook to get the retail rates and then use these rates to calculate the mortgage payment for the customers in the second workbook. We will use document properties to pass values from the Rates workbook to the Payment workbook. The Rates workbook has a Pivot Table that has interest rates and a cell that stores the margin. To make the sample work independently we have removed the connection to the external database and instead we get the data from another sheet in the workbook however that can be easily changed. Here is what the Rates workbook looks like. 0.75 Margin above the wholesale rates Values Row Labels Interest Rates Retail Rates 1 Year 4.5 5.25 3 Year 5 5.75 30 Year 5.875 6.625 5 Year 5.25 6 7 Year 5.5 6.25 The Payments workbook has information about the clients, their mortgage as well as cells where the retail mortgage rates can be updated. Mortgage Type Interest Rate 1 Year ARM 5 3 Year ARM 5.5 5 Year ARM 5.75 7 Year ARM 6 30 Year 6.375 Client Name Email Id Loan Type Interest Rate Loan Term in Years Principal Monthly Payment Jack jack@contoso.com 3 Year ARM 5.5 30 $350,000 $1,987.26 Judy judy@contoso.com 5 Year ARM 5.75 30 $400,000 $2,334.29 The following sections describe the steps involved with some code snippets. The complete code and the workbooks can be downloaded at the bottom of this post (see attachments). This is a console application and accepts the margin rate added for overhead as a parameter. We use a fixed constant in the workbook if no margin is specified. To simplify things I have omitted the error handling for the most part. You will definitely need to add robust error handling if you are planning to deploy it for a practical application. First print the margin rate and some initialization if (args.Length > 0) Console .WriteLine( "Margin rate is = " + args[0] + "%" ); // Instantiate the Web service and create a status array object. ExcelService es = new ExcelService(); Status[] outStatus; string ratesWorkbook = "http://server-name/Site/doclib//Rates.xlsx" ; // Set credentials for requests es.Credentials = System.Net.CredentialCache.DefaultCredentials; Now we open the workbook and set the margin rate in the Rates workbook, refresh data and calculate the retail rates. // Open the Rates workbook, get new rates by refreshing the external data and // calculate. string sessionId = es.OpenWorkbook(ratesWorkbook, "" , "" , out outStatus); //Set the input overhead margin rate if specified omcommand line. if (args.Length > 0) { es.SetCellA1(sessionId, "RatesSheet" , "Margin" , args[0]); } // Refresh data and recalculate the workbook. es.Refresh(sessionId, "" ); es.CalculateWorkbook(sessionId, CalculateType.CalculateFull); Now that the retail rates are calculated; we get the retail rates and set them as document properties on the Payments workbook. The advantages of using the document properties for storing values are firstly the properties are associated with the document so if you update the workbook they will still be preserved. Secondly since they are stored by SharePoint the process of calculating rates and payments can be done at different times if needed by the business process. //Get the calculated rates from the workbook double rate1Year, rate3Year, rate5Year, rate30Year; valObj = es.GetCellA1(sessionId, "RatesSheet" , "Rate1Year" , false , out outStatus); rate1Year = Convert .ToDouble(valObj); valObj = es.GetCellA1(sessionId, "RatesSheet" , "Rate3Year" , false , out outStatus); rate3Year = Convert .ToDouble(valObj); valObj = es.GetCellA1(sessionId, "RatesSheet" , "Rate5Year" , false , out outStatus); rate5Year = Convert .ToDouble(valObj); valObj = es.GetCellA1(sessionId, "RatesSheet" , "Rate30Year"...