490660
490660
download
https://ebookbell.com/product/professional-excel-services-shahar-
prish-981320
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
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
https://ebookbell.com/product/professional-excel-development-the-
definitive-guide-stephen-bullen-1275824
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
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
https://ebookbell.com/product/professional-microsoft-powerpivot-for-
excel-and-sharepoint-sivakumar-harinath-ron-pihlgren-denny-guangyeu-
lee-4106374
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
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
Credits
Acquisitions Editor Vice President and Executive Group Publisher
Katie Mohr Richard Swadley
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
Contents
xiv
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xv
Contents
xv
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xvi
Contents
xvi
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xvii
Contents
xvii
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xviii
Contents
xviii
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xix
Contents
xix
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xx
Contents
xx
04866ftoc.qxd:04866ftoc 3/15/07 8:32 PM Page xxi
Contents
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.
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.
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.
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.
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.
❑ 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:
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
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.
❑ 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
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.
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.
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
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).
5
04866c01.qxd:04866c01 3/15/07 8:33 PM Page 6
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.
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.
6
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 7
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.
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.
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.
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
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
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.
❑ 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).
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
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.
11
04866c02.qxd:04866c02 3/15/07 8:33 PM Page 12
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.
❑ 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
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
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
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
❑ 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
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
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.
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
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
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.
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
bother,
new married wife will not eat,
PLUM blossom
foot,
feet.
THE CAKE SELLER
ebookbell.com