SlideShare a Scribd company logo
Lab 13: Coding with Excel and Excel
Services

      Objectives
      After completing this lab, you will be able to:

      •   Use and publish an Excel workbook designed to that advantage of Excel Services
      •   Create a Trusted File Location in Excel Services
      •   Develop and external C# application that will use Excel Services Web Service

      Prerequisites
      Before working on this lab, you must have:
      •   Labs 1 and 2 fully completed

      Scenario
      This document shows how to build custom .Net code that incorporates server side Excel based
      logic into an application and calls the Excel Web Services to run the Excel calculation portion of
      the logic on the server.
      Specifically, the sample revolves around a “Monte Carlo” simulation model for a stock and
      option portfolio. The user runs a command line tool and passes some arguments to the command.
      The code passes the arguments to the server thru Web service method calls, and gets results back.
      It then outputs the results to the console.
      A console application was chosen for this sample because it enables us to easily show a complete
      application, while focusing on the Excel Web Services aspects, rather than on UI considerations.
      Key aspects demonstrated here:

          •   Spreadsheet based logic incorporated into enterprise server applications.
          •   Proprietary information (generally the formulas and calculation model) protected on the
              server. End users can use the model thru the application even if they don’t have access to
              the model itself.
          •   Business Analysts maintains the Excel formulas and calculation model portion of the
              application, without intervention of IT Developer or an Administrator.


      Estimated time to complete this lab: 60 minutes
Lab 13: Coding with Excel and Excel Services



Exercise 1
Publish an Excel workbook to a document library
                     In this exercise you will use an excel workbook to calculate the total value of X number of
                     stocks and options of a specific company. This workbook was designed to allow an external
                     application to use some of it fields by using labeled cells and the Excel Services Web
                     Service.

                    1. Create a new Team Site under “Sites” and call it “My Team Site”
                    2. Create a new Document Library within that site called “MonteCarlo” based on “MS
                       Office Excel spreadsheet” Document Template.
                    3. In the “MonteCarlo” document library click the down arrow beside settings, select
                       “Document Library Settings”, under the “General Settings” section, select “Advanced
                       settings”, locate the “Browser-enabled Documents” and select the “Display as a web
                       page” bullet. Click Ok
                    4. Return to the document library – click the “MonteCarlo” link in the breadcrumb




Exercise 2
Enable the new document library as a “Trusted File Location”
                    Make this location a “Trusted File Location” from the point of view of Excel Services


                    1. In the Central Administration, select Application Management
                    2. Select “Create or configure this farm's shared services”
                    3. Click on the SSP – in this case “O12ServerSSP1 (Default)” link
                    4. In the “Excel Services Settings” section, click on “Trusted file locations”
                    5. Click “Add Trusted File Location” located in the blue bar
                    6. Paste the URL of the “MonteCarlo” document library in the “Address” field. It should
                       look similar to the following:
                       (http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo)
                    7. Keep all other options as is an click Ok
                         Note: Only files published to trusted locations can be opened and used by Excel
                         Services.
                    8. Open the “MonteCarlo.xlsx” workbook located at “C:holMonteCarlo”.
                    Note: You need Excel 2007 in order to publish the workbook appropriately to the server.
                    Version 2003 or older of Excel does not have that functionality.
                    9. Notice the “Simulation” sheet!

                     The Simulation sheet is conceptually the proprietary calculation model, which we want to
                     protect on the server and use in an application. For this sample, the model is “fake” – just a
Lab 13: Coding with Excel and Excel Services    3


               few randomly generated numbers – but the workbook interface to the application is
               demonstrated just as if this was a real elaborated calculation model.

          10. In the File menu (Office logo top left hand corner), select “Publish”, then “Excel Services”.
              The “Save as” dialog opens.

          11. Just above the “Save” button, click the “Excel Services Options” button

              Note: A good practice would be to uncheck the Simulation sheet to protect your calculation
              model and make it unavailable for viewing on the server. The entire file is still copied over to
              the server location and available to the calculation components of the server, but only users
              with extended rights can view this sheet or open the entire file in Excel.

          12. Click Ok

          13. Uncheck the “Open this workbook in my browser after I save” box

          14. Browse to the “MonteCarlo” document library by selecting the “My Network Places” in the
              left hand side panel i.e.
              “http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo/” and click “save” to
              save your workbook at that location with the default file name.

          15. Your file is now published to a server document library. If you browse to the library, you’ll
              see your file listed.

          16. Your Browser will launch and will show the MonteCarlo.xlsx file. Notice that the Simulation
              tab is no available.

          17. Close Excel and the browser session.




Exercise 3
Developing the Monte Carlo Application
               This C# external application uses Excel Services Web Service and its calculation
               capabilities (formulas in the MonteCarlo spreadsheet) by passing four values – the company
               Symbol, the initial price, the strike price and lastly the interest rate – and wait for the
               calculated results which are display onto the console. You will build this application!

               ∑ Create a C# project
               1. Launch Visual Studio 2005 from the Desktop link

               2. Create a new project of type Visual C# / Windows and template “Console
                  Application” called “MonteCarlo”
               3. Save the project at the following location: C:HOLMonteCarlo (browse to that location
                  and click Ok.

               4. Add a web reference to the Excel Web Services:
                   http://hol.litwareinc.com/_vti_bin/excelservice.asmx
Lab 13: Coding with Excel and Excel Services


                    Note1: Visual Studio creates a proxy class for accessing the Web service. The class is
                    called ExcelService, and it is in the namespace <your-app><server-name>. In our
                    example, the namespace is: MonteCarlo.com.litwareinc.hol
                    Note2: The Excel Services Server name is “hol.litwareinc.com”
                5. Add a using statement to the new namespace:
                   using MonteCarlo.com.litwareinc.hol;

                6. Define the interface between your Console Application and the Excel workbook. The
                   interface is a set of named ranges that are associated with input and output cells. Insert
                   the following code:
                   class Program
                       {
                            // input & output cell names
                            private static string[] inputCells = {quot;Symbolquot;,
                   quot;InitialPricequot;, quot;StrikePricequot;, quot;InterestRatequot;};
                         private static string[] outputCells = {quot;Averagequot;,
                quot;VaRquot;, quot;RelDeltaNormalquot;};
                    Note: Both direct range references (e.g. “B52”) and named ranges can be used. Using
                    named ranges isolates the parameter location in the workbook from the application, thus
                    making the model more robust and easier to maintain.
               7. Add code to display a usage line when the command is run with an insufficient number
                  of arguments.
                       static void Main(string[] args)
                            {
                                if (args.Length < 1 + inputCells.Length)
                                {
                                    Console.Error.Write(quot;Usage: MonteCarlo
                    <WorkbookPath>quot;);
                                    foreach (string argName in inputCells)
                                        Console.Error.Write(quot; <{0}>quot;, argName);
                                    Console.Error.WriteLine(quot;quot;);
                                    return;
                                      }


                    Note: The usage line will help you in run-time. It mentions all required arguments – a
                    path to the server-side Excel workbook and the input cell names that you defined in the
                    previous step.
               8. Add code to instantiate and initialize the proxy object.
                    // Excel web services stuff:
                    // Instantiate and initialize the service proxy object
                                ExcelService xlSrv = new ExcelService();
                                xlSrv.Credentials =
                    System.Net.CredentialCache.DefaultCredentials;
                    Note: Setting credentials to DefaultCredentials means that your process security
                    context is passed along to the web service for authentication.
               9. Open the workbook and start a session with Excel Services.
                    // Open the workbook
Lab 13: Coding with Excel and Excel Services     5


    Status[] status;
    string sessionId = xlSrv.OpenWorkbook(args[0],
    string.Empty, string.Empty, out status);
    Note: The OpenWorkbook method returns a session ID, which is used in subsequent
    calls to the server as your session context.
    The two empty strings designate default cultures (languages) to be used – the context of
    your process.
    The “status” output argument returns an array of non-critical errors (usually empty).
    Critical errors are surfaced as SOAP exceptions that you can catch.
10. Set the values that were passed on the command line into cells in the workbook, using
    the array of input named ranges that you defined above.

    // Set parameter values into cells
    for (int i = 0; i < inputCells.Length; i++)
         status = xlSrv.SetCellA1(sessionId, quot;Sheet1quot;,
    inputCells[i], args[1+i]);

11. Call a method to make the server calculate the new state of the workbook.
    // Calculate the workbook.
    status = xlSrv.CalculateWorkbook(sessionId,
    CalculateType.Recalculate);
    Note: When the model is complex and time consuming to calculate, it is often a good
    idea to turn automatic recalculation off while authoring the workbook in Excel. When
    automatic recalculation is turned off, the server will not recalculate after each parameter
    value that you set, and you need to explicitly instruct the server to recalculate once all
    parameters are set.
12. Once the workbook is calculated, you can get output values from the server session,
    using the array of output named ranges that you defined above, and write them out.

// Get results and write them out.
foreach (string cellName in outputCells)
   {
          object result = xlSrv.GetCellA1(sessionId, quot;Sheet1quot;,
   cellName, true, out status);
          Console.WriteLine(quot;{0}:t{1}quot;, cellName, result);
       }

13. Lastly, close the workbook and your server session.
    // Close the session.
    status = xlSrv.CloseWorkbook(sessionId);
    Note: This is a very important optimization step. If you do not close the session when
    you are done with it, the server will still time it out after an administrator-controlled
    amount of time; but this timeout is usually set according to the needs of GUI-based
    applications, to allow users to pause between interactions. Unnecessary sessions that
    remain open consume server resources and may cause decreased overall performance.
14. Your application code is ready! Now have Visual Studio build it, and the development
    phase is done. On the menu, select Build, then Build MonteCarlo.
   The results of the build should be:
Lab 13: Coding with Excel and Excel Services


                    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========




Exercise 4
Running the Application
                    In this exercise you will test your external C# application along with the Excel Services
                    Web Service.

                   1. Open a command window: Start, command Prompt

                   2. Change to the Debug directory of your newly built project:

                        “C:HOLMonteCarloMonteCarlobinDebug”

                   3. Run your program without arguments to get the usage line. On the command line, enter:
                      “MonteCarlo”

                        You will be returned information about the usage of this program

                   4. Run your program, giving it the path to the server Excel workbook, and values to the
                      other arguments. Notice the three result values that are written out. Enter: “MonteCarlo
                      “http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo/MonteCarlo
                      .xlsx” MSFT 26 31 5%” at the command line.
                   5. Try with different numbers
                   6. Do not close the console yet… From the server document library, open the workbook for
                      editing in Office Excel 2007. Click on the file’s context menu then, select Edit in
                      Microsoft Office Excel.
                   7. Once in Excel, select cell A15 of Sheet1, where the Average output value is. Notice its
                      value.
                   8.   Modify the cell and multiply it by 10. The resulting calculation should look like
                        =Simulation!B3*10.
                   9. Then save the file and quit Excel.
             10. In the command window again, simply run the last command once more, to execute your
                 program again with the same set of input values. Notice how the Average result is now an
                 order of magnitude larger!
             11. You made this change in the algorithm without touching a line of code – just modifying the
                 Excel calculation model.
                   Close all applications - this lab is completed!

More Related Content

What's hot

HP ArcSight Asset Model Import FlexConnector Developer's Guide
HP ArcSight Asset Model Import FlexConnector Developer's GuideHP ArcSight Asset Model Import FlexConnector Developer's Guide
HP ArcSight Asset Model Import FlexConnector Developer's Guide
Protect724tk
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
People code events 1
People code events 1People code events 1
People code events 1Samarth Arora
 
Asset Model Import FlexConnector Developer's Guide
Asset Model Import FlexConnector Developer's GuideAsset Model Import FlexConnector Developer's Guide
Asset Model Import FlexConnector Developer's Guide
Protect724migration
 
Oracle apex-hands-on-guide lab#1
Oracle apex-hands-on-guide lab#1Oracle apex-hands-on-guide lab#1
Oracle apex-hands-on-guide lab#1Amit Sharma
 
User hook implemantation sample example
User hook implemantation  sample exampleUser hook implemantation  sample example
User hook implemantation sample example
Ashish Harbhajanka
 
Asset modelimportconn devguide_5.2.1.6190.0
Asset modelimportconn devguide_5.2.1.6190.0Asset modelimportconn devguide_5.2.1.6190.0
Asset modelimportconn devguide_5.2.1.6190.0
Protect724
 
Test script
Test scriptTest script
Test script
Bharathi P
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration tool
Ravi Kumar Lanke
 
Oa Framework Tutorial
Oa Framework TutorialOa Framework Tutorial
Oa Framework Tutorialnolimit797
 
Excel 2007 Unit N
Excel 2007 Unit NExcel 2007 Unit N
Excel 2007 Unit N
Raja Waseem Akhtar
 
B ex query designer
B ex query designerB ex query designer
B ex query designer
Praveen Konduru
 
Oracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning TutorialOracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning Tutorial
Rakesh Gujjarlapudi
 
AIA101.1.MS Access Tables & Data
AIA101.1.MS Access Tables & DataAIA101.1.MS Access Tables & Data
AIA101.1.MS Access Tables & Data
Dan D'Urso
 
Oracle Application Framework Cases
Oracle Application Framework Cases Oracle Application Framework Cases
Oracle Application Framework Cases
Feras Ahmad
 
People soft workflow by surya 2
People soft workflow by surya 2People soft workflow by surya 2
People soft workflow by surya 2meghamystic
 

What's hot (18)

HP ArcSight Asset Model Import FlexConnector Developer's Guide
HP ArcSight Asset Model Import FlexConnector Developer's GuideHP ArcSight Asset Model Import FlexConnector Developer's Guide
HP ArcSight Asset Model Import FlexConnector Developer's Guide
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
People code events 1
People code events 1People code events 1
People code events 1
 
Asset Model Import FlexConnector Developer's Guide
Asset Model Import FlexConnector Developer's GuideAsset Model Import FlexConnector Developer's Guide
Asset Model Import FlexConnector Developer's Guide
 
Oracle apex-hands-on-guide lab#1
Oracle apex-hands-on-guide lab#1Oracle apex-hands-on-guide lab#1
Oracle apex-hands-on-guide lab#1
 
User hook implemantation sample example
User hook implemantation  sample exampleUser hook implemantation  sample example
User hook implemantation sample example
 
Basic Oracle Usage v1
Basic Oracle Usage v1Basic Oracle Usage v1
Basic Oracle Usage v1
 
Asset modelimportconn devguide_5.2.1.6190.0
Asset modelimportconn devguide_5.2.1.6190.0Asset modelimportconn devguide_5.2.1.6190.0
Asset modelimportconn devguide_5.2.1.6190.0
 
Test script
Test scriptTest script
Test script
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration tool
 
Oa Framework Tutorial
Oa Framework TutorialOa Framework Tutorial
Oa Framework Tutorial
 
Excel 2007 Unit N
Excel 2007 Unit NExcel 2007 Unit N
Excel 2007 Unit N
 
B ex query designer
B ex query designerB ex query designer
B ex query designer
 
Oracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning TutorialOracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning Tutorial
 
AIA101.1.MS Access Tables & Data
AIA101.1.MS Access Tables & DataAIA101.1.MS Access Tables & Data
AIA101.1.MS Access Tables & Data
 
Oracle Application Framework Cases
Oracle Application Framework Cases Oracle Application Framework Cases
Oracle Application Framework Cases
 
Jazz
JazzJazz
Jazz
 
People soft workflow by surya 2
People soft workflow by surya 2People soft workflow by surya 2
People soft workflow by surya 2
 

Viewers also liked

2014 simulations
2014 simulations2014 simulations
2014 simulations
Kate FLR
 
Monte carlo simulation
Monte carlo simulationMonte carlo simulation
Monte carlo simulationMissAnam
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management System
ĞĔŃÚĨŃĔ ĞĔŃĨÚŚ
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management System
Pranil Dukare
 
[PPT] Hospital management system - Quanta-his
[PPT] Hospital management system - Quanta-his[PPT] Hospital management system - Quanta-his
[PPT] Hospital management system - Quanta-his
Birlamedisoft Pvt. Ltd
 
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
NICHOLAS RATEMO
 
Hospital management system project
Hospital management system projectHospital management system project
Hospital management system projectHimani Chopra
 

Viewers also liked (8)

2014 simulations
2014 simulations2014 simulations
2014 simulations
 
Stats chapter 6
Stats chapter 6Stats chapter 6
Stats chapter 6
 
Monte carlo simulation
Monte carlo simulationMonte carlo simulation
Monte carlo simulation
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management System
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management System
 
[PPT] Hospital management system - Quanta-his
[PPT] Hospital management system - Quanta-his[PPT] Hospital management system - Quanta-his
[PPT] Hospital management system - Quanta-his
 
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
PROJECT-HOSPITAL MANAGEMENT SYSTEM CHAP. 1 TO 4
 
Hospital management system project
Hospital management system projectHospital management system project
Hospital management system project
 

Similar to ( 13 ) Office 2007 Coding With Excel And Excel Services

XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricksguest92a5de
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksEarl Grau
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Oracle application express
Oracle application expressOracle application express
Oracle application express
Abhinaw Kumar
 
Creating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherCreating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisher
Samchi Fouzee
 
Oracle application express ppt
Oracle application express pptOracle application express ppt
Oracle application express pptAbhinaw Kumar
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
Rich Helton
 
Eclipse e4 Overview
Eclipse e4 OverviewEclipse e4 Overview
Eclipse e4 Overview
Lars Vogel
 
Intellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdfIntellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdf
Modern Modular NY.
 
Publishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialPublishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialSebastian Correa Gimenez
 
Hands-on Lab: Migrating Oracle to PostgreSQL
Hands-on Lab: Migrating Oracle to PostgreSQL Hands-on Lab: Migrating Oracle to PostgreSQL
Hands-on Lab: Migrating Oracle to PostgreSQL
Amazon Web Services
 
770_0629.pdf dump for oracle cloud interface
770_0629.pdf dump for oracle cloud interface770_0629.pdf dump for oracle cloud interface
770_0629.pdf dump for oracle cloud interface
lknam1982
 
XPages Blast - Lotusphere 2011
XPages Blast - Lotusphere 2011XPages Blast - Lotusphere 2011
XPages Blast - Lotusphere 2011
Tim Clark
 
websphere cast iron labs
 websphere cast iron labs websphere cast iron labs
websphere cast iron labs
AMIT KUMAR
 

Similar to ( 13 ) Office 2007 Coding With Excel And Excel Services (20)

XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricks
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & Tricks
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Oracle application express
Oracle application expressOracle application express
Oracle application express
 
Creating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherCreating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisher
 
Oracle application express ppt
Oracle application express pptOracle application express ppt
Oracle application express ppt
 
Excel
ExcelExcel
Excel
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Eclipse e4 Overview
Eclipse e4 OverviewEclipse e4 Overview
Eclipse e4 Overview
 
Intellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdfIntellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdf
 
Publishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorialPublishing geoprocessing-services-tutorial
Publishing geoprocessing-services-tutorial
 
Hands-on Lab: Migrating Oracle to PostgreSQL
Hands-on Lab: Migrating Oracle to PostgreSQL Hands-on Lab: Migrating Oracle to PostgreSQL
Hands-on Lab: Migrating Oracle to PostgreSQL
 
770_0629.pdf dump for oracle cloud interface
770_0629.pdf dump for oracle cloud interface770_0629.pdf dump for oracle cloud interface
770_0629.pdf dump for oracle cloud interface
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
XPages Blast - Lotusphere 2011
XPages Blast - Lotusphere 2011XPages Blast - Lotusphere 2011
XPages Blast - Lotusphere 2011
 
websphere cast iron labs
 websphere cast iron labs websphere cast iron labs
websphere cast iron labs
 

More from LiquidHub

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
LiquidHub
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade processLiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovementsLiquidHub
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share pointLiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server DeploymentLiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install DatabasesLiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment DetailLiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup StrategiesLiquidHub
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration StepsLiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007LiquidHub
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughLiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshLiquidHub
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshLiquidHub
 

More from LiquidHub (20)

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
 
5060 A 01
5060 A 015060 A 01
5060 A 01
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

( 13 ) Office 2007 Coding With Excel And Excel Services

  • 1. Lab 13: Coding with Excel and Excel Services Objectives After completing this lab, you will be able to: • Use and publish an Excel workbook designed to that advantage of Excel Services • Create a Trusted File Location in Excel Services • Develop and external C# application that will use Excel Services Web Service Prerequisites Before working on this lab, you must have: • Labs 1 and 2 fully completed Scenario This document shows how to build custom .Net code that incorporates server side Excel based logic into an application and calls the Excel Web Services to run the Excel calculation portion of the logic on the server. Specifically, the sample revolves around a “Monte Carlo” simulation model for a stock and option portfolio. The user runs a command line tool and passes some arguments to the command. The code passes the arguments to the server thru Web service method calls, and gets results back. It then outputs the results to the console. A console application was chosen for this sample because it enables us to easily show a complete application, while focusing on the Excel Web Services aspects, rather than on UI considerations. Key aspects demonstrated here: • Spreadsheet based logic incorporated into enterprise server applications. • Proprietary information (generally the formulas and calculation model) protected on the server. End users can use the model thru the application even if they don’t have access to the model itself. • Business Analysts maintains the Excel formulas and calculation model portion of the application, without intervention of IT Developer or an Administrator. Estimated time to complete this lab: 60 minutes
  • 2. Lab 13: Coding with Excel and Excel Services Exercise 1 Publish an Excel workbook to a document library In this exercise you will use an excel workbook to calculate the total value of X number of stocks and options of a specific company. This workbook was designed to allow an external application to use some of it fields by using labeled cells and the Excel Services Web Service. 1. Create a new Team Site under “Sites” and call it “My Team Site” 2. Create a new Document Library within that site called “MonteCarlo” based on “MS Office Excel spreadsheet” Document Template. 3. In the “MonteCarlo” document library click the down arrow beside settings, select “Document Library Settings”, under the “General Settings” section, select “Advanced settings”, locate the “Browser-enabled Documents” and select the “Display as a web page” bullet. Click Ok 4. Return to the document library – click the “MonteCarlo” link in the breadcrumb Exercise 2 Enable the new document library as a “Trusted File Location” Make this location a “Trusted File Location” from the point of view of Excel Services 1. In the Central Administration, select Application Management 2. Select “Create or configure this farm's shared services” 3. Click on the SSP – in this case “O12ServerSSP1 (Default)” link 4. In the “Excel Services Settings” section, click on “Trusted file locations” 5. Click “Add Trusted File Location” located in the blue bar 6. Paste the URL of the “MonteCarlo” document library in the “Address” field. It should look similar to the following: (http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo) 7. Keep all other options as is an click Ok Note: Only files published to trusted locations can be opened and used by Excel Services. 8. Open the “MonteCarlo.xlsx” workbook located at “C:holMonteCarlo”. Note: You need Excel 2007 in order to publish the workbook appropriately to the server. Version 2003 or older of Excel does not have that functionality. 9. Notice the “Simulation” sheet! The Simulation sheet is conceptually the proprietary calculation model, which we want to protect on the server and use in an application. For this sample, the model is “fake” – just a
  • 3. Lab 13: Coding with Excel and Excel Services 3 few randomly generated numbers – but the workbook interface to the application is demonstrated just as if this was a real elaborated calculation model. 10. In the File menu (Office logo top left hand corner), select “Publish”, then “Excel Services”. The “Save as” dialog opens. 11. Just above the “Save” button, click the “Excel Services Options” button Note: A good practice would be to uncheck the Simulation sheet to protect your calculation model and make it unavailable for viewing on the server. The entire file is still copied over to the server location and available to the calculation components of the server, but only users with extended rights can view this sheet or open the entire file in Excel. 12. Click Ok 13. Uncheck the “Open this workbook in my browser after I save” box 14. Browse to the “MonteCarlo” document library by selecting the “My Network Places” in the left hand side panel i.e. “http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo/” and click “save” to save your workbook at that location with the default file name. 15. Your file is now published to a server document library. If you browse to the library, you’ll see your file listed. 16. Your Browser will launch and will show the MonteCarlo.xlsx file. Notice that the Simulation tab is no available. 17. Close Excel and the browser session. Exercise 3 Developing the Monte Carlo Application This C# external application uses Excel Services Web Service and its calculation capabilities (formulas in the MonteCarlo spreadsheet) by passing four values – the company Symbol, the initial price, the strike price and lastly the interest rate – and wait for the calculated results which are display onto the console. You will build this application! ∑ Create a C# project 1. Launch Visual Studio 2005 from the Desktop link 2. Create a new project of type Visual C# / Windows and template “Console Application” called “MonteCarlo” 3. Save the project at the following location: C:HOLMonteCarlo (browse to that location and click Ok. 4. Add a web reference to the Excel Web Services: http://hol.litwareinc.com/_vti_bin/excelservice.asmx
  • 4. Lab 13: Coding with Excel and Excel Services Note1: Visual Studio creates a proxy class for accessing the Web service. The class is called ExcelService, and it is in the namespace <your-app><server-name>. In our example, the namespace is: MonteCarlo.com.litwareinc.hol Note2: The Excel Services Server name is “hol.litwareinc.com” 5. Add a using statement to the new namespace: using MonteCarlo.com.litwareinc.hol; 6. Define the interface between your Console Application and the Excel workbook. The interface is a set of named ranges that are associated with input and output cells. Insert the following code: class Program { // input & output cell names private static string[] inputCells = {quot;Symbolquot;, quot;InitialPricequot;, quot;StrikePricequot;, quot;InterestRatequot;}; private static string[] outputCells = {quot;Averagequot;, quot;VaRquot;, quot;RelDeltaNormalquot;}; Note: Both direct range references (e.g. “B52”) and named ranges can be used. Using named ranges isolates the parameter location in the workbook from the application, thus making the model more robust and easier to maintain. 7. Add code to display a usage line when the command is run with an insufficient number of arguments. static void Main(string[] args) { if (args.Length < 1 + inputCells.Length) { Console.Error.Write(quot;Usage: MonteCarlo <WorkbookPath>quot;); foreach (string argName in inputCells) Console.Error.Write(quot; <{0}>quot;, argName); Console.Error.WriteLine(quot;quot;); return; } Note: The usage line will help you in run-time. It mentions all required arguments – a path to the server-side Excel workbook and the input cell names that you defined in the previous step. 8. Add code to instantiate and initialize the proxy object. // Excel web services stuff: // Instantiate and initialize the service proxy object ExcelService xlSrv = new ExcelService(); xlSrv.Credentials = System.Net.CredentialCache.DefaultCredentials; Note: Setting credentials to DefaultCredentials means that your process security context is passed along to the web service for authentication. 9. Open the workbook and start a session with Excel Services. // Open the workbook
  • 5. Lab 13: Coding with Excel and Excel Services 5 Status[] status; string sessionId = xlSrv.OpenWorkbook(args[0], string.Empty, string.Empty, out status); Note: The OpenWorkbook method returns a session ID, which is used in subsequent calls to the server as your session context. The two empty strings designate default cultures (languages) to be used – the context of your process. The “status” output argument returns an array of non-critical errors (usually empty). Critical errors are surfaced as SOAP exceptions that you can catch. 10. Set the values that were passed on the command line into cells in the workbook, using the array of input named ranges that you defined above. // Set parameter values into cells for (int i = 0; i < inputCells.Length; i++) status = xlSrv.SetCellA1(sessionId, quot;Sheet1quot;, inputCells[i], args[1+i]); 11. Call a method to make the server calculate the new state of the workbook. // Calculate the workbook. status = xlSrv.CalculateWorkbook(sessionId, CalculateType.Recalculate); Note: When the model is complex and time consuming to calculate, it is often a good idea to turn automatic recalculation off while authoring the workbook in Excel. When automatic recalculation is turned off, the server will not recalculate after each parameter value that you set, and you need to explicitly instruct the server to recalculate once all parameters are set. 12. Once the workbook is calculated, you can get output values from the server session, using the array of output named ranges that you defined above, and write them out. // Get results and write them out. foreach (string cellName in outputCells) { object result = xlSrv.GetCellA1(sessionId, quot;Sheet1quot;, cellName, true, out status); Console.WriteLine(quot;{0}:t{1}quot;, cellName, result); } 13. Lastly, close the workbook and your server session. // Close the session. status = xlSrv.CloseWorkbook(sessionId); Note: This is a very important optimization step. If you do not close the session when you are done with it, the server will still time it out after an administrator-controlled amount of time; but this timeout is usually set according to the needs of GUI-based applications, to allow users to pause between interactions. Unnecessary sessions that remain open consume server resources and may cause decreased overall performance. 14. Your application code is ready! Now have Visual Studio build it, and the development phase is done. On the menu, select Build, then Build MonteCarlo. The results of the build should be:
  • 6. Lab 13: Coding with Excel and Excel Services ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== Exercise 4 Running the Application In this exercise you will test your external C# application along with the Excel Services Web Service. 1. Open a command window: Start, command Prompt 2. Change to the Debug directory of your newly built project: “C:HOLMonteCarloMonteCarlobinDebug” 3. Run your program without arguments to get the usage line. On the command line, enter: “MonteCarlo” You will be returned information about the usage of this program 4. Run your program, giving it the path to the server Excel workbook, and values to the other arguments. Notice the three result values that are written out. Enter: “MonteCarlo “http://hol.litwareinc.com/SiteDirectory/MyTeamSite/MonteCarlo/MonteCarlo .xlsx” MSFT 26 31 5%” at the command line. 5. Try with different numbers 6. Do not close the console yet… From the server document library, open the workbook for editing in Office Excel 2007. Click on the file’s context menu then, select Edit in Microsoft Office Excel. 7. Once in Excel, select cell A15 of Sheet1, where the Average output value is. Notice its value. 8. Modify the cell and multiply it by 10. The resulting calculation should look like =Simulation!B3*10. 9. Then save the file and quit Excel. 10. In the command window again, simply run the last command once more, to execute your program again with the same set of input values. Notice how the Average result is now an order of magnitude larger! 11. You made this change in the algorithm without touching a line of code – just modifying the Excel calculation model. Close all applications - this lab is completed!