0% found this document useful (0 votes)
11 views84 pages

490660

The document is about 'Professional Excel Services' by Shahar Prish, providing an overview of Excel Services and its functionalities. It includes information on the author, publication details, and various recommended Excel-related products available for download. The content covers topics such as user administration, programmability options, and Excel Web Services.

Uploaded by

duuttulian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views84 pages

490660

The document is about 'Professional Excel Services' by Shahar Prish, providing an overview of Excel Services and its functionalities. It includes information on the author, publication details, and various recommended Excel-related products available for download. The content covers topics such as user administration, programmability options, and Excel Web Services.

Uploaded by

duuttulian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Professional Excel Services Shahar Prish

download

https://ebookbell.com/product/professional-excel-services-shahar-
prish-981320

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Excel Mastery An Ultimate Step By Step Guide To Learn Essential


Functions Formulas And Charts In 7 Days For Beginner To Professional
Sarker Ryans

https://ebookbell.com/product/excel-mastery-an-ultimate-step-by-step-
guide-to-learn-essential-functions-formulas-and-charts-in-7-days-for-
beginner-to-professional-sarker-ryans-56901572

Professional Excel Development The Definitive Guide To Developing


Applications Using Microsoft Excel Vba And Net 2nd Edition Second
Edition Rob Bovey

https://ebookbell.com/product/professional-excel-development-the-
definitive-guide-to-developing-applications-using-microsoft-excel-vba-
and-net-2nd-edition-second-edition-rob-bovey-2538842

Professional Excel Development The Definitive Guide Stephen Bullen

https://ebookbell.com/product/professional-excel-development-the-
definitive-guide-stephen-bullen-1275824

Microsoft Excel Professional 2021 Guide Ca Manmeet Singh Mehta

https://ebookbell.com/product/microsoft-excel-professional-2021-guide-
ca-manmeet-singh-mehta-47260322
Microsoft Excel Vba Professional Projects 1st Edition Duane Birnbaum

https://ebookbell.com/product/microsoft-excel-vba-professional-
projects-1st-edition-duane-birnbaum-973414

Professional Microsoft Powerpivot For Excel And Sharepoint Sivakumar


Harinath

https://ebookbell.com/product/professional-microsoft-powerpivot-for-
excel-and-sharepoint-sivakumar-harinath-50318536

Professional Financial Computing Using Excel And Vba 1st Edition Lai

https://ebookbell.com/product/professional-financial-computing-using-
excel-and-vba-1st-edition-lai-55161894

Professional Microsoft Powerpivot For Excel And Sharepoint Sivakumar


Harinath Ron Pihlgren Denny Guangyeu Lee

https://ebookbell.com/product/professional-microsoft-powerpivot-for-
excel-and-sharepoint-sivakumar-harinath-ron-pihlgren-denny-guangyeu-
lee-4106374

Microsoft Excel 2007 A Professional Approach Spi Kathleen Stewart

https://ebookbell.com/product/microsoft-excel-2007-a-professional-
approach-spi-kathleen-stewart-10960254
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page iii

Professional
Excel®Services

Shahar Prish
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page ii
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page i

Professional
Excel®Services
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page ii
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page iii

Professional
Excel®Services

Shahar Prish
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page iv

Professional Excel®Services
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana


Published simultaneously in Canada
ISBN: 978-0-470-10486-6
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1

Library of Congress Cataloging-in-Publication Data


Prish, Shahar, 1975-
Professional Excel Services / Shahar Prish.
p. cm.
Includes bibliographical references.
ISBN 978-0-470-10486-6 (paper/website)
1. Microsoft Excel (Computer file)--Handbooks, manuals, etc. 2. Business--Computer programs. I. Title.
HF5548.4.M523P76 2007
005.54--dc22
2007006215
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under
Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the
Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center,
222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permis-
sion should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis,
IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO


REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE
CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED
OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED
HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTAND-
ING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PRO-
FESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT
PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL
BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS
REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMA-
TION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE
ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READ-
ERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR
DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services please contact our Customer Care Department within
the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and
other countries, and may not be used without written permission. Microsoft and Excel are registered trademarks
of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their
respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be avail-
able in electronic books.
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page v

To my parents, Tzila and Danny — thank you


04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page vi
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page vii

About the Author


Shahar Prish was born and raised in Israel. He was playing around with computers for 10 years or
so when suddenly and unexpectedly it became a useful skill to have. At the age of 16, Shahar started
working in a company that did various backup and encryption applications for the PC. When he turned
18 he was drafted to the army where he defended his country from behind a keyboard, a monitor, and
way too much non-dairy chocolate bread-spread. When he got out of the army, he tried to get a degree
in CS, but failed miserably due to work getting in the way. He worked for a big telecommunication
company (where he developed software for international calls fraud detection) and in a small startup
(which did something with browsers — it was never really clear). In 1998 he was the first employee in a
small company called “Maximal Innovative Intelligence” that developed Business Intelligence software.
In 2001 Maximal was purchased by Microsoft and the product it was selling was rebranded and sold as
“Microsoft Data Analyzer”. From Maximal, eleven employees moved over to the US where they started
working in the Office group. A year after moving, Shahar started working with the rest of the team on
Excel Services (then called Excel Server). After spending most of his life writing code, Shahar intends
to keep doing so until the medics pry the keyboard from his dead cold hands.
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page viii
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page ix

Credits
Acquisitions Editor Vice President and Executive Group Publisher
Katie Mohr Richard Swadley

Senior Development Editor Vice President and Executive Publisher


Tom Dinse Joseph B. Wikert

Technical Editor Compositor


Justin Rockwood Laurie Stewart, Happenstance Type-O-Rama

Production Editor Proofreader


Debra Banninger Sossity Smith

Copy Editor Indexer


Foxxe Editorial Services Melanie Belkin

Editorial Manager Anniversary Logo Design


Mary Beth Wakefield Richard Pacifico

Production Manager
Tim Tate
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page x
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page xi

Acknowledgments

Thanks to:

❑ The team at Wrox and especially Katie and Tom for making this book possible
❑ Justin for giving me great feedback when editing the book and for making sure all my t’s were
crossed
❑ Eran for helping when it was difficult to transform what I was thinking into words and for help-
ing with ideas for some of the solutions in the book
❑ The Excel Services team for helping with some of the issues that came up during the writing of
the book.
04866ffirs.qxd:04866ffirs 3/15/07 8:31 PM Page xii
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xiii

Content

Acknowledgments xi
Introduction xxiii

Part I: Introducing Excel Services 1

Chapter 1: Introduction to Excel Services 3


Why Use Excel Services 3
The Excel Client Farms 4
Rewriting the Models 4
How Excel Services Comes to the Rescue 5
Excel Services Goals 5
First Goal — 100% Fidelity with Excel 6
Second Goal — Security 6
Third Goal — Robustness and Reliability 6

Chapter 2: User and Administrator Cheat Sheet 7


Excel 2007 and Excel Services 7
Object Model Support 7
Addin Model Support 8
Excel Services Out of the Box 8
Excel Web Access 8
Topologies 9
Departmental Deployment 10
Large Scale Deployment 10
Unsupported Features 10
Old File Format 10
VBA 10
Query Tables 11
External Workbooks 11
Real-Time Data 11
Images and Shapes 11
Protection/Encryption 12
Other Unsupported Features 12
Roundtrip-Only Features 12
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xiv

Contents

How to Administer Excel Services 12


Excel Services Settings 13
Trusted File Locations 14
User Defined Function Assemblies 15
Summary 15

Chapter 3: Inside Excel Services 17


Session, State, and Workbooks 17
Caches 18
Workbook Caches 18
Data Caches 19
Caching Calculations 19
Summary 20

Chapter 4: Programmability Options 21


Excel Web Services 21
Opening and Closing the Workbook 21
Getting Values from the Workbook 22
Writing Values to the Workbook 22
Workbook-level Interaction 22
Getting a Whole Workbook 23
Miscellaneous Methods 23
User Defined Function Assemblies 23
EWA Web Part 23
Summary 23

Part II: Excel Web Services 25

Chapter 5: Hello World Sample 27


Hello World Overview 27
Preparing the Project and Opening a Workbook 28
Making Sure the File Can Be Accessed by Excel Services 28
Preparing the Project for Use with Excel Services 30
Opening a Workbook on the Server 32
Getting a Cell from the Workbook 34
Writing Values into Cells in the Workbook 35
Using the Model Part of the Workbook 36

xiv
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xv

Contents

Finishing the Sample Project 36


Updating the Model 37
Extras 38
Final Program 38
C# Hello World Program 38
VB.NET Sample Code 40
Summary 41

Chapter 6: Excel Web Services Reference 43


Direct Linking 43
Notations Used in the API Reference 43
Session Management Methods 44
OpenWorkbook 44
CloseWorkbook 46
CancelRequest 46
GetSessionInfo 48
Cell Retrieval Methods 49
Common Characteristics for GetXXX Methods 49
GetCell 52
GetCellA1 53
GetRange 54
GetRangeA1 55
Workbook Retrieval 56
GetWorkbook 57
Writing Values into Cells 57
Type and Content Restrictions with Set Methods 57
SetCell 58
SetCellA1 59
SetRange 59
SetRangeA1 60
Workbook Updating Methods 61
Calculate 62
CalculateA1 63
CalculateWorkbook 64
Refresh 64
Support Classes and Enumerations 66
RangeCoordinates 66
Status 66

xv
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xvi

Contents

Exceptions and Errors 66


SoapException 67
SubCode List 68
Summary 70

Chapter 7: Building the Excel Services Library (ESL) 71


Project Design 72
Abstraction Classes 72
Namespace 73
Support Classes 74
Method Call Abstraction 76
IExcelServiceWrapper 77
IWrapperCredentials 78
Modifying ExcelServiceSoap 78
Exception Classes 80
ExcelServices Class 80
ExcelServicesType 80
Implementing ExcelServices 80
ExcelServices.Open() 82
ExcelServices.FromSessionId() 83
The Session Class 83
Dispose Code 85
Refresh Functionality 87
GetRangeA1 Functionality 88
Session Class Summary 89
The RangeResult Class 89
Example 90
How RangeResult Works 91
WorkbookData Class 96
Summary 97

Part III: User Defined Functions 99

Chapter 8: UDF Sample 101


What This Sample Contains 101
Creating a UDF Assembly 101
Required References 102
Adding the UDF Class 103
Adding the First UDF 103
Optional Parameters 108

xvi
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xvii

Contents

Getting External Data 109


Using Ranges with UDFs 111
Caching Information 115
Summary 118

Chapter 9: UDF Reference 119


History 119
Excel Services UDFs 120
Execution of UDFs 120
UDF Requirements 120
The Assembly Loading Process under the Hood 121
UDF Classes’ Lifetime 122
UDF Methods 122
Cell Ranges 127
UDFs and Interop 128
Thread Safety 128
Volatility of UDFs 129
Personal Data UDFs 130
Caching Information in UDF Classes 132
Loading UDFs on the Server 134
Updating Assemblies 134
Troubleshooting UDFs 136
Debugging UDFs 138
Summary 140

Chapter 10: Client Support for Server UDFs 141


Modifying UDFs to Run on the Client 141
Add COM Support to a UDF Assembly 142
Registering the Assembly 144
Using the UDF inside Excel Client 144
Adding Client Support for GetMultiStockQuote 145
Conclusion 147
Generic Client UDF Support 147
Configuration Application 148
UdfProxy 149
CUdfAutomation 159
Final Steps 169
Improvements 170
Other Generic Solutions 170
Summary 171

xvii
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xviii

Contents

Part IV: Excel Web Access 173

Chapter 11: Using Excel Web Access 175


EWA Usage 175
Web Part Properties 177
Part to Part Communication 179
Inside EWA 181
Frame Communication 182
Session Cookie 182
Summary 182

Part V: Reusable Excel Web Services Projects 183

Chapter 12: Utilizing Web Services in UDFs 185


Library Component 185
How It Works 186
About Code Generation 186
WebServiceMethodCollection and WebServiceMethod Classes 187
WebServiceParameter and WebServiceParameterCollection Classes 189
UdfDefinition Class 189
GeneratedResult Class 195
Helper Class 200
ExcelServicesHelper Class 203
ExcelHelper Class 206
UI Component 209
Summary 211

Chapter 13: Custom Web Services 213


Overview 213
Usage Example 214
Using the Custom Web Service 218
Updating the Model 219
More Type Safety 219
Generating UDFs 219
Topology 219
Coding the Solution 221
Solution Structure 221
Library 222

xviii
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xix

Contents

Excel Addin 223


Web Application 230
Enumerating Web Services 233
Summary 234

Chapter 14: RSS over Excel Services 235


Overview 235
What Is RSS 236
Usage Example 236
Coding the Solution 245
Solution Structure 245
Library 245
Excel Addin 247
RSS Server 250
Summary 257

Chapter 15: Excel Services as an RTD Server 259


Overview 260
Use 260
Coding the Solution 262
How RTD Works on the Client 262
ClientSideRtd 263
Summary 271

Chapter 16: Real Time Data UDF 273


Overview 273
Use 274
Dangers of Using RTD in Excel Services 275
Coding the Solution 276
RtdUdf Project 277
Summary 285

Chapter 17: Directly ParameterizedWorkbooks 287


Overview 287
Use 287
CustomWorkbooks Project 291
Summary 295

xix
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xx

Contents

Chapter 18: SQL Tables and SharePoint Lists 297


Overview 297
Use 298
Coding the Solution 306
Pes.DataUdfs Project 306
OleDbUdfs Class 311
SharePointUdfs Class 311
Summary 316

Chapter 19: External Workbook References 319


Overview 319
Use 321
Coding the Solution 328
Pes.DataUdfs Project 328
Utils Class 337
Summary 337

Chapter 20: Excel Services Workflows 339


Overview 339
Use 340
Coding the Solution 347
Pes.ExcelWorkflows Project 347
Deploying the Solution 365
Summary 368

Chapter 21: EWA Projects 369


Parameterized EWA Links 369
How It Works 369
How to Build 370
Custom XLViewer 376
How It Works 376
Coding the Solution 379
Manipulating the EWA Session 382
How It Works 382
Coding the Solution 384
Summary 392

xx
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xxi

Contents

Chapter 22: Excel Data Filter 393


Overview 393
Use 394
Coding the Solution 401
The Excel Services AJAX library 401
How Part to Part Works 406
Pes.Filter Project 407
Summary 418

Chapter 23: Excel Services Mashup 419


Overview 419
Use 419
Coding the Solution 423
Workbook Model 423
EWA Page 424
UDF Assembly 425
HTML 425
Summary 430

Index 431

xxi
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xxii
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxiii

Introduction

Excel spreadsheets are used practically everywhere — they are the cornerstone of many applications and
businesses. Excel Services revolutionizes the spreadsheet world by introducing server-side spreadsheet
calculation and rendering with unparallel Excel fidelity. This book will guide developers through under-
standing what Excel Services is, how to work with it, and how to develop applications on top of it.

It is rather embarrassing to say, but it took me a whole three years to understand just how useful Excel
Services is. It was after I gave (what I thought was) a well-received demo at Office DevCon in Redmond
with Danny Khen, a program manager on the Excel Services team. I remember going through the parts
of the demo: One of the first things I showed was how to extract a column of data from an Excel work-
sheet and utilize it in an ASP.NET application. The crowd applauded, which threw me off-guard because
I thought I hadn’t really gotten to the cool part yet. A few days later I was at a birthday party for the
daughter of Boaz Chen, a friend and coworker who moved here from Israel with me (and who also hap-
pens to work on Excel Services). I remember standing in the doorway on our way out when it suddenly
hit me. Even that simple operation of getting a column of data from Excel is incredibly useful. It basically
means you can use Excel Services just like the client version is used — as a miniature database application.
This opens up a world of new scenarios! See, until that moment, from a programmatic point of view, I was
looking at Excel Services only from the “Excel model” angle — as a really neat way of calculating a com-
plex model without having to resort to rewriting it or to creating whole Excel farms.

Shortly after the presentation I started getting emails from people who found out about me through my
blog. And there again it was revealed to me just how blind I was. People were using Excel Services for
various things I never thought about, everything from building an auditing mechanism for charging for
usage of Excel models to running iterative simulations in financial markets.

One of the things that these exchanges confirmed was the fact that I really like working with other devel-
opers and trying to help them find solutions to their problems. And here I was in a perfect position to do
this, and since this is Excel we are talking about, I figured I was in a perfect position to help a potentially
large number of developers. That is around the time when the idea of writing this book came along — a
way of giving many developers a starting point when trying to attack a problem with Excel Services.

Who This Book Is For


If you are an independent developer and have built applications on Excel or have used a spreadsheet as a
starting point for code, this book is for you. If you are a developer working in an organization which relies
on Excel spreadsheets for modeling, handling, and storing data and you want to see how these processes
can be streamlined and be leveraged more than ever before, this book is for you. If you are a developer
who likes new technologies and are looking for new ways to solve both old problems and new ones, this
book is for you.

This book is targeted at developers who are comfortable in the .NET environment. The coding examples
in the later chapters use mostly C# — however, they can all be implemented in pretty much any other
.NET-supporting language. While this book assumes some knowledge of .NET, the first examples in the
book also go through the basics of creating projects. One project (in Chapter 10) is written using C++/CLI
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxiv

Introduction
(managed extensions for C++) for technical reasons. That chapter can be skipped by readers with no C++
knowledge — the solution can be used as is. The details are given for people who are more interested in
the intricacies of how the solution actually works.

What This Book Covers


The first half of this book provides detailed explanations about the various programmability options
Excel Services offers. It delves into specifics as well as warning against problematic areas developers
have to look out for. This includes Excel Web Services, the Excel Services UDF (User Defined Functions)
extension mechanism and a bit of information about the EWA (Excel Web Access). When they’re done
reading this part, developers will have a good grasp of how to extend and work against Excel Services.

The second half of the book gives some ideas for solutions that can be written by using Excel Services.
Some of the solutions are more generic than others and may be usable as is by developers. Other solu-
tions are good “stepping stones” towards other, more elaborate solutions. Furthermore, some solutions
complement each other and have more value when used together.

How This Book Is Str uctured


The parts that explain Excel Web Services and UDFs both have three chapters each. The first chapter of
each part presents a small “hello world” example that makes use of the technology. The second chapters
provide deep, detailed explanation about the technology. The third chapters in each of these parts shows
how to code a useful solution that can be reused by developers (in the case of the Excel Web Services part)
or by users (in the case of the UDF part).

The second half of the book contains examples of reusable projects — each chapter here is divided into
three main sections. The first section shows how the example can be used. The second section goes into
detail about how the example is coded. The last section, where it exists, talks about some of the possible
improvements that can be made in the example.

Generally speaking the examples in the second half of the book require you to understand the explana-
tions shown in the first half.

What You Need to Use This Book


To make full use of this book, the following products and resources are needed:

❑ Access to a Microsoft Office SharePoint Server (Enterprise edition) installation.


❑ Visual Studio 2005 (or newer). Developers can make do with any other development environ-
ment that can create .NET 2.0 assemblies for UDFs. Older versions of Visual Studio 2003 can be
used to access Excel Web Services; however, the experience may be different from that described
in the book.
❑ Excel 2007

xxiv
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxv

Introduction

Conventions
To help you get the most from the text and keep track of what’s happening, we’ve used a number of
conventions throughout the book.

Boxes like this one hold important, not-to-be forgotten information that is directly
relevant to the surrounding text.

Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

❑ We highlight in italic type new terms and important words when we introduce them.
❑ We show keyboard strokes like this: Ctrl+A.
❑ We show file names, URLs, and code within the text like so: persistence.properties.
❑ We present code in two different ways:
In code examples we highlight new and important code with a gray background.
The gray highlighting is not used for code that’s less important in the present
context, or has been shown before.

Source Code
As you work through the examples in this book, you may choose either to type in all the code manually or
to use the source code files that accompany the book. All of the source code used in this book is available
for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Search
box or by using one of the title lists) and click the Download Code link on the book’s detail page to obtain
all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is
978-0-470-10486-6.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you
can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to
see the code available for this book and all other Wrox books.

Errata
We make every effort to ensure that there are no errors in the text or in the code. However, no one is
perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or
faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save
another reader hours of frustration and at the same time you will be helping us provide even higher-
quality information.

xxv
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxvi

Introduction
To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one
of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all
errata that has been submitted for this book and posted by Wrox editors. A complete book list including
links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport
.shtml and complete the form there to send us the error you have found. We’ll check the information
and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions
of the book.

p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based
system for you to post messages relating to Wrox books and related technologies and interact with other
readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of
your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts,
and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you
read this book but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click the Register link.


2. Read the terms of use and click Agree.
3. Complete the required information to join as well as any optional information you wish to
provide, and click Submit.
4. You will receive an e-mail with information describing how to verify your account and
complete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you
must join.

Once you join, you can post new messages and respond to messages other users post. You can read mes-
sages at any time on the web. If you would like to have new messages from a particular forum e-mailed
to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques-
tions about how the forum software works as well as many common questions specific to P2P and Wrox
books. To read the FAQs, click the FAQ link on any P2P page.

xxvi
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxvii

Professional
Excel®Services
04866flast.qxd:04866flast 3/15/07 9:28 PM Page xxviii
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 1

Part I: Introducing
Excel Services

Chapter 1: Introduction to Excel Services

Chapter 2: User and Administrator Cheat Sheet

Chapter 3: Inside Excel Services

Chapter 4: Programmability Options


04866c01.qxd:04866c01 3/15/07 8:33 PM Page 2
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 3

Introduction to
Excel Ser vices

So why do you care about Excel Services? Well, since you bought this book, there is a chance your
organization uses Excel in its day-to-day operation. Who can blame them? Excel is the most popular
modeling tool and the most popular database tool. It is so versatile that the same person can use it
for both a complex financial model and a simple task list. In the Excel organization, for example,
it is not uncommon to use Excel for managing tasks, project milestones, and bug reports. Over the
years, Excel has gathered a very large set of features ranging from advanced formatting to advanced
data acquisition mechanisms. With Excel 2007, this set of features has been bolstered even more to
allow Excel to be a first-class BI (business intelligence) tool.

Why Use Excel Ser vices


While Excel is a great tool, it really lacks in one specific area: it is a client application. It was designed
to be a client application from the get-go, and in all probability it will stay that way. That means it is
focused on one user getting whatever Excel functionality that user needs on a PC. There are many
indicators showing that organizations will want to run Excel on the server:

❑ For one, a lot of people go to great lengths to try to get Excel client to work in a server
environment — at great cost and with great frustration.
❑ People want one version of the truth — but when workbook files are used with Excel
client, there is no real protection against people modifying them. With only the client at
the users’ disposal, it is much harder to keep a single version that will be the “single
point of entry” to the data.
❑ Intellectual property is expensive, and companies want to guard it. Excel models can
become extremely complex and give a real edge to their owners. Those owners do not
want others to be able to access the models — only the results of the models. Excel
does not really supply such protection.
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 4

Part I: Introducing Excel Services


❑ Running a lot of models, whether as part of a mechanized process or because a lot of users need
to get at the data, is virtually impossible to do in a scalable manner with Excel.
❑ To see any part of an Excel file, the entire file must be opened. This can put a strain on even the
fastest networks and can be completely impractical when people are connecting over a WAN.

More accurately, in some cases Excel is smart enough to delay-load some types of data caches such as
pivot tables.

❑ People want to see and navigate Excel worksheets inside a browser. But they also want those
worksheets to be up to date, and they want the ability to navigate them and do simple opera-
tions such as drilling down through information or filtering lists.
❑ Administrators want more manageability of what Excel does. Some workbooks have complex
data queries that, when executed by too many users at the same time, can bring databases
to their knees. Conversely, some data sources are accessible only to specific users. For these
reasons, workbooks that are distributed may sometimes only have copies of data rather than
actual live data. This raises the “one version of the truth” problem — how can organizations
know what data is current?

For these reasons and others, organizations end up producing various creative solutions to the problem.
These solutions usually come in two flavors: large, custom-built farms of Excel client applications and
rewriting the underlying models.

The Excel Client Farms


Excel farms are relatively large farms (or computing clusters) that run multiple instances of Excel on
request. People usually build some kind of protocol that allows them to extract information from the
Excel processes and transfer it back to the user in whatever form is desired.

These solutions, while creative and impressive, do not scale well and are not fun to maintain. They
require a lot of hardware due to various Excel limitations (again that pesky “was not designed for the
server” thing), and managing the whole thing is really hard to do.

Rewriting the Models


The other solution organizations come up with, which is no less painful (and in some ways, more painful),
is to take tried-and-true models written in Excel and rewrite them in some other language so that they can
be used without Excel. This is of course a huge time investment — not only can the models be excessively
complex, but when a model changes, the code needs to be updated appropriately, which takes a lot of time
(testing alone is a major time sink, since one needs to make sure that the model behaves the same way that
it does in Excel).

Note that, in some cases at least, the reason for transferring models into code does not have to do with
the inability to get server capabilities but rather is done to squeeze every ounce of performance out of a
model. Excel Services may or may not help in these cases. Some organizations will retain their need to
rewrite Excel models.

4
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 5

Chapter 1: Introduction to Excel Services

How Excel Services Comes to the Rescue


Excel Services has been created to solve all these problems and more. While still using portions of Excel
code that have been rewritten to be serverworthy, large amounts of work has been done around that code
to make it into an actual server product.

Excel Services solves some of the problems simply by virtue of being a server product — intellectual
property is protected because users do not have access to the actual workbook (unless the admin allows
them to see it). Since all the calculations are done on the server, it is not even an issue — there is no need
to transfer the model itself to the user. This also takes care of the “one version of the truth” issue — there
is a central repository for information, and only people who are allowed to update that repository will.
Furthermore, because Excel Services is leveraging the SharePoint infrastructure, it can make use of such
features as “view-only rights” where some users can access the complete file (by loading it in Excel or by
saving it to their hard drive), while others can only view it through the server.

Because it is a server, it can also do various things that the client was never designed to do, such as shar-
ing information across users. The file itself need not be loaded more than once. This not only reduces
network traffic, but it also means that the actual process of loading the file, which can be very long
and CPU-intensive for large models, is only done once. This is doubly true for models that rely on
getting data from databases — Excel Services can figure out what data is sharable among which
users and make sure that it does not query the database too many times. On top of that, the adminis-
trators can also instruct Excel Services to only hit the database server periodically — say, not more
than once every 5 minutes — giving them much more control over how many times the database
will be hit by requests.

Since Excel Services was built from the ground up to have multiple instances of the same workbook open
at any given time, it is possible for multiple users to open any number of workbooks and work with them.
The same goes for processes that need concurrent access to workbooks. The number of workbooks that
can be interacted with at a given moment is only limited by memory and CPU.

Finally, because the server supplies the means to access parts of loaded workbooks, people who are across
the WAN will not need to take the hit of loading the entire file — they can just request a small part of the
workbook. This also ties into EWA (Excel Web Access), which is a Web Part that allows people to navigate
Excel workbooks inside a browser (no ActiveXs, I repeat, no ActiveXs at all, just plain old HTML and
JavaScript, honest).

Excel Ser vices Goals


It is important to understand what our goals were when we started thinking and designing Excel Services.
Understanding the goals explains a lot of the technical decisions we made throughout the project. I am
only listing the goals that have specific bearings on our server product — obviously goals such as cus-
tomer satisfaction are there by default.

5
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 6

Part I: Introducing Excel Services

First Goal — 100% Fidelity with Excel


Our first and foremost goal was to have 100% fidelity with Excel in every Excel feature we support.
That is to say, if we support a given Excel feature, our goal is to support it in exactly the same manner
that Excel 2007 supports it. It does not mean, though, that we support all of Excel’s features.

That said, sometimes when things are transferred to a server environment, “100% fidelity” stops being
a clear-cut thing. As an example, take the Data Refresh feature. In Excel, when the user refreshes the
data, Excel will go and grab new data from the database back end. On the server, as described before,
the administrator can place a limit on how often refreshes may occur.

Second Goal — Security


It is incredibly important that Excel Services does not expose information to unauthorized users. If a user
does not have access to a workbook, that person should never be able to use Excel Services to circumvent
that principle (unless the administrator specifically set up the server for that). Similarly, if a workbook is
set up such that users should not be able to see the actual models and formulas of the workbook, Excel
Services should never supply that information to users.

Additionally, users should never be able to see information that belong to other users. So, if a user accesses
data and gets a set of results and a second user gets a different set of results, neither of them should be able
to see the results of the other.

Third Goal — Robustness and Reliability


Since this is a server product, robustness and reliability are paramount — we want to be able to keep
the server up and running for as long as possible. If there is a feature in Excel that is impossible to
translate well to the server because it will reduce robustness or reliability, there is a good chance we
will preemptively decide not to do it at all.

6
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 7

User and Administrator


Cheat Sheet

This chapter gives an overview of the differences between Excel 2007 and Excel Services, what
Excel Server can do right out of the box, the various topologies available when deploying Excel
Services, and a cheat sheet for how to do basic administration of Excel Services.

Excel 2007 and Excel Ser vices


Excel and Excel Services can process the same files and come up with the exact same results. This
sometimes leads people to think that Excel Services is simply “Excel running on the server.” This
misconception can give rise to expectations that Excel Services cannot satisfy.

Throughout the book I will use “Excel” as shorthand for “Microsoft Excel 2007” — the client
software — and “Excel Services” as shorthand for ”Microsoft Office SharePoint Server —
Excel Services.”

It is important to understand that the fact that Excel runs on a client machine, with one user, makes it
wildly different from Excel Services, which has many users all at the same time. This brings us to the
first major difference between Excel Services and Excel: there is no object model in Excel Services.

Object Model Support


Yes, you read correctly: Excel Services does not expose an automation object model (OM) in the tra-
ditional manner. There is no endless list of objects with properties and collections. There is not even
a short list of them. The only way to automate Excel Services is through the supplied set of methods
exposed by Excel Web Services. Those methods contain a set of primitives that allow developers not
so much to automate Excel features but to work with the Excel model embedded in a workbook. In
the first version of Excel Services, it was a not a goal to allow people to author workbooks on the
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 8

Part I: Introducing Excel Services


server but rather to allow them to make use of workbooks. Therefore, it became far less important to
supply an OM. Furthermore, given the way that Excel Services is programmed (and because it does
not support VBA) adding an OM would have meant creating an object model in .NET. Implementing
an object model that diverges from that of Excel would have created an instant backward-compatibility
issue. When we do create an OM, it should be something that works both on the client and on the server
so that solutions written for one can be leveraged by the other.

Addin Model Support


With the exception of support for UDFs (user defined functions), there is no real support for addins on
the server. This means that there is no way to extend Excel Services the way that some solutions extend
Excel — from within.

This does not prevent people from using Excel Services inside their solutions, however. On the contrary;
it is much easier, and by far more scalable, to do that with Excel Services than it is with Excel. However,
the standard addins that people write for Excel cannot be used with this version of Excel Services.

Excel Ser vices Out of the Box


There are three primary ways to interact with Excel Services. The only one that works “out of the box,”
though, is Excel Web Access (EWA), which allows you to see workbooks rendered inside a browser in a
truly thin manner. The other two are the Excel Web Services and UDFs. I will touch on those later.

Excel Web Access


Much the same way that Outlook Web Access (OWA) allows users to see their Exchange inbox in
a browser, EWA allows users to see, navigate, and interact with workbooks on the server. EWA is
implemented as a Web Part in SharePoint, where it can be used to build dashboard and SharePoint
applications.

The EWA team did a truly amazing job at keeping Excel Services faithful to Excel 2007, where humanly
(and sometimes even inhumanly) possible, which is no small feat when you consider all the new visual
features of Excel Services. Almost all visual features that are supported by Excel Services have near-
complete fidelity to the way things look in Excel 2007, when using Internet Explorer 6 (IE 6) or above.

Although Firefox 1.5 is a supported browser, some visual features are only available in IE 6 or above.

See if you can detect which one of the images in Figure 2.1 is from EWA and which one is from Excel
Services.

For integration inside SharePoint smart-pages, EWA also supports the part-to-part SharePoint feature,
allowing you to connect it to other Web Parts to create an integrated application.

Being a Web Part, the EWA can also be used in applications. It has properties that can be modified to
change its behavior and so on. I will give a few examples of the ways you can utilize it inside and out-
side SharePoint.

8
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 9

Chapter 2: User and Administrator Cheat Sheet

Figure 2.1

Topologies
Excel Services can be deployed in various ways, each targeting a different scenario. The diagram in
Figure 2.2 shows the general-case deployment.

The back-end server(s) are running Excel Services. The front-end server(s) are running the SharePoint
portal product and the EWA Web Part, which together allow you to build dashboards that contain Excel
Services features.
Browser

Fire
IE
Fox

Sharepoint Sharepoint
Portal Portal
Front-End

Services Services

Content DB

EWA EWA
Back-End

Excel Excel
Services Services …

Figure 2.2

9
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 10

Part I: Introducing Excel Services

Departmental Deployment
In some cases the back end, front end, and content DB will all be installed on the same machine. This is
especially useful in cases where there is a small group of trusted people using the server (that is where
“departmental” comes from). This is also the way I would recommend you test your Excel Services solu-
tion because there will be less noise when debugging.

Large Scale Deployment


Excel Services scales well both up and out. Scaling up means that administrators can throw better hard-
ware at an Excel Services machine and expect to get better performance. Scaling out means that they
can add more machines to a server farm that will be able to handle extra load. Excel Services has a few
schemes for load balancing that allow the administrator to determine how Excel Services will handle
traffic coming in to multiple machines. (You can see them in the “Excel Services Settings” section later
in this chapter.)

Unsuppor ted Features


When we started out with Excel Services, we knew that our goal was to support almost all of the features
of Excel. However, we also knew that this is something we would not be able to get into the product with
the first version. So, we have tried to have a clear story about what we support and what we do not sup-
port. While what’s unsupported is well documented, I thought I would touch on some items and explain
the logic behind them. I believe that most of the features that are currently unsupported will be added in a
future version or service pack. The only one that I am pretty sure will never make its way onto the server
is VBA support.

Excel Services has two types of features it does not support:

❑ Roundtrip-only features. Excel Services will load workbooks containing these features and will
even know how to create workbooks containing these features when the user opens the work-
book through the Open in Excel toolbar button. However, these features will not be displayed
in EWA or be accessible through the API.
❑ Unsupported features. These features are completely unsupported, meaning that workbooks con-
taining them will fail to load in the EWA or through the application programming interface (API).

Old File Format


Early in the process we decided to support only the new .xlsx and .xlsb Excel file formats. This was
mainly due to the fact that we did not want to rewrite all the old Excel code to make it serverworthy. We
had a chance to start from scratch and get code with high reliability and robustness that could be used
on the server, so we went with that route. Since Excel 2007 comes with converters that allow you to mass
convert files, this should not be painful for most users.

VBA
Visual Basic for Applications (VBA) was the one feature we knew for a fact would not make it into the
product. There was never even a question about it. Bringing VBA into the server would have been colossal
work, if it even would have even been possible. Remember, in addition to fidelity to Excel 2007, other

10
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 11

Chapter 2: User and Administrator Cheat Sheet


very important features are reliability and robustness. VBA is a pretty antiquated technology that was
never intended to run on a server. As such, it would have been impossible to get it up and running with
server quality without a total rewrite.

We knew from the beginning that this was going to be a painful point for our users. However, in the
long run it was the right thing to do. Had we tried to patch VBA to work properly on the server, we
probably would have missed many of our deadlines and would have ended up with a subpar server
to boot. Which brings us to the next painfully missing feature: query tables.

Query Tables
Query tables are the Excel feature that allows users to bring in tabular data from relational databases.
PivotTables are a more elaborate feature that allows users to slice and dice the data in a table, where
the rows and columns originate from the data itself (or from an Analysis Services cube).

Excel Services does not currently support query tables When we started out, it was obvious to us that we
had to choose between that and PivotTables. In the end, PivotTables won (mainly because at least some
of the functionality that query tables has can be exposed by PivotTables).

External Workbooks
Excel allows people to reference cells and ranges from other workbooks. With Excel Services, this poses
quite a few problems. You reference workbooks by their path. With Excel Services and SharePoint docu-
ment libraries as our preferred storage, this does not make much sense. On top of that, in Excel, when
multiple workbooks are open, they share the calculation chain. This mechanism would have been diffi-
cult to translate to the server in version 1.

One of the sample solutions presented in this book will allow you to get data from external workbooks
that are accessible to Excel Services.

Real-Time Data
Excel supports a feature called Real Time Data (RTD). This is basically a push-model cell data feature
where a custom component notifies Excel when it has new data. Excel will then go and get that data and
update the sheet, causing a recalculation. This has the net effect of making Excel update its calculation,
potentially very often, due to new incoming data.

Since both “clients” of Excel Services (that is, EWA and the Web Service API) are pull models (i.e., calls
are made from client to server and the server cannot notify client on changes), there was very little sense
in adding support for the RTD feature.

That said, this book will provide an example showing how you can still leverage existing RTD servers
with Excel Services, with some limitations.

Images and Shapes


Excel Services will not load workbooks that contain images or shapes — another of the things that
would have been nice to have but just did not make the final cut.

11
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 12

Part I: Introducing Excel Services

Protection/Encryption
Excel Services comes with built-in protection — if administrators do not wish for a workbook to be
accessed, they are provided with various tools to ensure this.

Other Unsupported Features


This is a partial list of the other features that are unsupported in Excel Services:

❑ ActiveX controls
❑ Comments
❑ Controls/forms
❑ Embedded OLE objects
❑ Ink annotations
❑ Pictures/clipArt/shapes
❑ SmartTags
❑ Text queries
❑ Web queries
❑ XLM sheets (macros)
❑ XML mapping

Roundtrip-Only Features
The following features will not prevent a workbook from loading, but they will not be accessible either:

❑ Freeze panes
❑ Split windows
❑ Custom views
❑ XML expansion packs

How to Administer Excel Ser vices


As this is a “how to program Excel Services” type of book and is not meant as a detailed administration
guide, this section will only go into those details that are appropriate for the content of the book. It will dis-
cuss a standalone deployment and assumes that Excel Services is already installed. When there is a major
difference between a standalone deployment and a more complex one, I will call that out specifically. That
said, I will be providing an overview of what Excel Services deployments one can expect and what to look
out for with them.

Various parts of this book may require you to make changes to the configuration of Excel Services. The
main entry point for that can be found in the following location on your server:

http://<servername>:<port>/ssp/admin/default.aspx

12
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 13

Chapter 2: User and Administrator Cheat Sheet


To find your port (and get to the main administration site of your SharePoint server), you can go to
Start/Control Panel/Administrative Tools/Microsoft Windows SharePoint Services
3.0. That will bring you to the Central Administration page of your SharePoint server. When that
page comes up, you will find your port number in the address bar. Another way of getting to the Excel
Services administration site is to click the link under Shared Services Administration on the left side of
the Central Administration page.

Regardless to how you get there, you should see the configuration options for all your installed servers.
In this example, the server has only Excel Services installed, so that is the only option shown in
Figure 2.3.

From this page, you can reach all the possible configuration options of Excel Services.

Figure 2.3

Excel Services Settings


This section contains the basic Excel Server settings. The only option that may affect the various examples
in this section is the Maximum Sessions Per User option.

Sessions will be discussed more thoroughly later when session and state are discussed (see the next
chapter for more information), but for now it is enough to understand that each time a user or process
interacts with Excel Services, it does so from within a session. A session can be discarded in one of two
ways — either the caller explicitly closes it or it will time out. This setting limits the amount of concur-
rently opened sessions a user can have. For most purposes, the defaults should be enough. However, in

13
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 14

Part I: Introducing Excel Services


some cases, the same user identity may need to open many concurrent sessions that stay open for a long
time on the server. In such cases, this value may need to be increased.

Trusted File Locations


Excel Services will not open files from just any location. The administrator needs to specify what locations
are available for users. Any attempt to open a file that resides in storage other than a trusted location (TL for
short), will fail. For that reason, when developing and testing your solutions, it is important to make sure
that the place from which you are loading files is trusted. Each trusted location has its own settings. This is
especially useful in installations where some locations are safer and more secure than others. For example,
say that you have two trusted locations — one that contains “Administrator-sanctioned” workbooks and
one to which employees can upload any old file. You can see that the “Administrator-sanctioned” location
is a “safer” location that is more frequently tested and checked for problems, so it will not have any adverse
effects on the server. Settings such as Maximum Workbook Size and Maximum Request Timeout can be
increased considerably to allow more functionality.

The important configuration options are:

❑ Address and Location Type. This is the actual URL that points to your trusted location. This
can either be a network share (\\server\share\directory), an HTTP location (http://
www.fileserver.com/ExcelFiles), or a SharePoint document library (http://companyweb/
sites/accounting/Shared Documents). Some features may only work when a file is pub-
lished to a SharePoint site. It is important to understand that this is the server name should
never be localhost or 127.0.0.1 — it has to be something that’s reachable by the user.

The most notable such feature is workbook parameters support in EWA. This feature will only work
when an Excel Workbook was published to a SharePoint document library.

❑ Trust Children. When this is checked, all folders under the one specified in the Address setting
will also be treated as trusted locations.
❑ Session Timeout and Short Session Timeout. This is explained in detail in the next chapter,
where sessions are discussed in depth.
❑ Maximum Request Duration. When a request reaches the server, there is a limit on how long
it will be allowed to execute. Once that time has passed, the server will do its best to cancel the
request and return it to the caller. If your solution requires you to often make calls to the server
that take a long time to execute, you may want to change this value. The default is 300 seconds
(which is 5 minutes).

Some operations on the server cannot be canceled immediately. This is why you may at times see
requests timing out after the allotted time.

❑ Volatile Functions Cache Lifetime. This is explained in detail in the next chapter.
❑ Allow User Defined Functions. The administrator can decide for each trusted location whether or
not it allows UDFs to run inside its workbooks. If this option is not checked, any advanced UDFs
you added to Excel Services will not work. This is the number one gotcha when writing UDFs —
if you forget to check this, your UDFs will not execute in your workbook.

14
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 15

Chapter 2: User and Administrator Cheat Sheet

User Defined Function Assemblies


User defined functions are managed .NET assemblies that contain functions that are callable from within
cells. This allows the developer to augment the existing Excel Services function library and is one of the
ways we can add features back into Excel Services. Each such assembly needs to be registered in this part
of the configuration.

Make sure to choose the correct option here — either File or GAC (Global Assembly Cache) — choos-
ing an incorrect one will cause your assembly to fail when loading and leave you scratching your head
as to why this is happening.

Summar y
When developing software that works with Excel Services, it is useful for developers to understand
how to administer the server, both when they want to test edge cases and when they need the server
to be configured a certain way for their solution to work optimally. This chapter discussed the most
common administration tasks developers will undertake — more advanced configurations may
sometimes be needed but are out of the scope of this book.

15
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 16
04866c03.qxd:04866c03 3/15/07 8:34 PM Page 17

Inside Excel Ser vices

There are various technical details one needs to understand about Excel Services for the rest of the
book to make sense. Even though some of this information may not have an immediate impact on
how you use, or even program against, Excel Services, it will help you understand what happens
under the hood.

Session, State, and Wor kbooks


When programming Excel Services, it is incredibly important to understand exactly how sessions
fit in.

All interaction with Excel Services revolves around workbooks that are loaded, queried, and manip-
ulated. When a workbook is needed, it is loaded into a session. What happens internally is this:

1. The server brings up the file and copies it locally (more on that when I discuss workbook
caches) if it has not already done so.
2. It loads the workbook into memory if it has not already done so. This loaded workbook
will be used as a “template” or as an “initial state.”
3. Finally, a session is opened, and the workbook “template” is assigned to the session where
it will be used. The session will have its own private copy as needed, and it will not affect
the globally loaded workbook. In that way, the changes users make to the workbooks they
load are isolated. A user making a change to a workbook will not see changes made to that
same workbook by a different user.

No interaction with workbooks can be achieved without a session, and no session can exist that
does not refer to a specific workbook. When a session expires (for any reason), all the information
it holds expires with it. That means that if you make changes to a workbook and the session you
04866c03.qxd:04866c03 3/15/07 8:34 PM Page 18

Part I: Introducing Excel Services


work against is closed, all your changes will be lost. Open sessions on the server have a unique ID
(Session ID) associated with them. That ID is used to interact with the session throughout its lifetime.

To further explain this, consider the simple workbook shown in Figure 3.1. It has two cells, A1 and A2.

Figure 3.1

A2 contains a very simple formula. In this case, it would be equal to 2. For this example, say that you
have two users loading the workbook, one after another and manipulating it:

❑ Jay opens a session asking for Workbook1.xlsx. If the workbook is not available, the server
will load it and go through the stages of making it available for users.
❑ Jay gets the cell in A2. The value Jay will see is “2” since that value was originally loaded
with the workbook.
❑ Jay sets the cell in A1 to “40.9” and gets the cell in A2. The value Jay will get from A2 will
now be “41.9”, just as if Jay were to open the file in Excel and place “40.9” in A1.
❑ From a different computer, Zoe also opens a session asking for Workbook1.xlsx.
❑ Zoe gets the value from A2. Zoe will see the value “2” — she will not see any of the changes
Jay made to the workbook since the two versions are isolated; they start out the same but they
do not affect each other in any way.

It is important to understand that, from the users’ point of view, they are the only one interacting with the
workbook — nobody else can affect what they see in the workbook. The server makes sure to keep the
workbooks isolated.

Generally speaking, Excel Services will not allow more than one request to a session at the same time.
That is why the EWA may sometimes display a message saying that “there is currently a request running
on this session, please try again later.” That said, there are a few types of requests that can be made con-
currently on a session. For more information about that, see the API references in Chapter 5.

Caches
Excel Services employs multiple levels of caching to ensure that requests can be executed as fast and
with as little impact on the system as possible.

Workbook Caches
As stated before, Excel Services caches what data it can to provide faster response to users. Workbooks
are cached on various levels.

18
04866c03.qxd:04866c03 3/15/07 8:34 PM Page 19

Chapter 3: Inside Excel Services

Workbook Disk Cache


When a user asks for a workbook for the first time, that workbook is fetched from its remote location to
the local disk. Once in the disk cache, the workbook will be deleted only when it is stale (i.e., when a
newer workbook is available) or if space is needed in the cache (and since the cache defaults to 40GB, it
is rare that additional space will be needed). Because memory is scarcer than disk space, there are cases
in which workbooks that were in memory will be discarded (since they are not being used anymore)
only to be reloaded from the local disk when requested again. This saves us from having to bring the
file over the network every time the file is needed. The server also makes sure that it has current files.
Whenever a workbook is opened, the server checks the “Last modified” property of the workbook. If
there is a new workbook available, the server will fetch the new one.

Loaded Workbook Cache


Once a workbook has been brought to the local server, it will be loaded into memory. This loaded repre-
sentation of the file will continue to exist in memory for as long as somebody is still using the workbook.
Like most Excel Services caches, it may continue to exist in memory as long as there is no memory pres-
sure on the server. Only the first request for the workbook will take the hit of going through the loading
process — subsequent requests will use the loaded workbook.

Workbooks that are loaded under two different locales or in different time zones may need to be loaded
more than once into memory. For example, a workbook loaded by a user using the Japanese locale and
one loaded by a user using the Hebrew locale will cause two copies of the workbook to be loaded into
memory. This is due to the fact that some very basic things behave differently with some locales and
so have potentially completely different memory representations.

Shared Workbook Cache


It often happens that multiple users can share the same workbook. The obvious example is a workbook
that is completely devoid of data queries or other volatile data. All users who open such a workbook will
get the same result, no matter what. In those cases, Excel Services will only ever have one copy of that
workbook in memory, which will be shared among users. This holds true in more complex cases, too. If
Excel Services detects that two different users can share the same piece of data (and from that deduce that
the whole workbook is identical for both users), it will make sure that only one copy of that workbook
exists in memory.

Data Caches
When workbooks contain external data, that data may or may not be sharable by two different users.
Moreover, say that a workbook contains two data queries — one sharable and one not. Excel Services
will manage separate caches for each data source, allowing users to share results where possible.

Caching Calculations
Calculations are cached as part of the Shared Workbook Cache described previously. The important thing
to note is that Excel Services is configured by default to minimize calculations of volatile functions.

Volatile functions are defined as functions that may return different results for the same parameters. A
good example is the Excel built-in NOW() function. It has no parameters and yet it returns different results

19
Exploring the Variety of Random
Documents with Different Content
I mounted a chair, on a horse I was
borne,
I
blew on a drum, and I beat on a horn.
THE LITTLE GIRL'S DREAM

HERE was a little girl


and she dreamed,
folks say,
That her future
mother-in-
law came
one day,
And gold and
plated
presents brought,
nd a flowered gown and embroidered coat.
PAT A CAKE

AT a cake, pat a cake,


Little girl fair,
There's a priest in the temple
Without any hair.

You take a tile,


And I'll take a brick,
And we'll hit the priest
In the back of the neck.
THE GREAT WALL

HE wily Emperor, Ch'in Shih


Huang,
He built a wall both great and strong;
The steps were narrow, but the wall was
stout,
So it kept the troublesome Tartars out.
A DILEMMA

ARD worm beans


Without any bother,
A wife he has married
And doesn't want his
mother.
He must leave his mother,
Or quarrel with his wife,
And thus they are separated
All their life.
CRUEL LITTLE GLUTTON

E ate too much,


That second brother,
And when he had eaten
He beat his mother.
UNFORTUNATE

E pulled up the wick


With the candlestick
knife,
And found he had married
A bald-headed wife.

Her eyes were askew,


And her mouth was awry,
And the silly old fellow
Was so mad he
could cry.
THE BRIDE

NEWLY made kettle is


bright,
A newly bought pig is a

bother,
new married wife will not eat,

But cries and thinks of her mother.


A BAD BOY

HERE was a little


fellow,
Who was mischievous,
they say,
They sent him to the melon-
patch
To watch it all the day.
They told him he must stay
there
Till the melons all were white,
nd not come home to mama,
Not even in the night.
THE CROWS

OOK at the white-breasted


crows overhead!
My father shot once, and ten
crows tumbled dead.
When boiled or when fried,
they taste very good,
But skin them, I tell you,
there's no better food.
FRIENDS OF THE HOUSE

HE thieving old magpie


has taken our food,
The chicken eats millet as if it
were good,
The faithful old watch-dog
looks after the house,
And the cat has come over to
catch us a mouse.
MY TEACHER AND I

S the sun came up, a ball


of red,
My teacher rode on his horse
ahead,
While I followed
close on my
dragon steed,
He by
the street.
and I by
the mead.
BUMP

UMP, bump go away,


Do not let our mama
see;
If she sees you on baby's
head,
She'll give no money for
nurse's bread.
A RIDDLE

PLUM blossom

foot,

And a pudding face sweet,


He's taller when he's sitting

Than when standing on his

feet.
THE CAKE SELLER

Y pretty little son,


I love him best of all,
Three years I have not seen
him,
And he's grown so very tall.
My horse he can ride,
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like