[Point=2]
Here is the longer answer… a full list of what your code can do with Excel Web Services: 下面是Excel Web Services代码的全部列表:
• GetApiVersion: Get a version string of the installed web service API build. • GetApiVersion:获取所安装的网络服务器API架构的版本字符串。 • sessionId = OpenWorkbook: Open a server-side calculation session. The method takes a workbook file path, and a few other arguments, and returns a sessionId. • sessionId = OpenWorkbook:打开服务器端计算会话。这个方法返回工作薄文件路径和一些其它参数,并返回一个服务器会话ID。 • GetSessionInformation: Get a few properties of the server session, primarily the language context of the session. • GetSessionInformation:获取一些服务器会话属性,主要是会话语言文本。 • SetCell: Set a value into a cell on one of the workbook’s sheets. Two flavors of this method exist: one takes a cell address (e.g “B52”) or a named range (e.g. “Interest”), and the other accepts integer coordinates, for cases where it is more convenient for your code to use them (typically when you have indexes in the code and want to use them to index the sheet). • SetCell:对工作薄中某一工作表上的单元格设置值。有两种方法:一种使用单元格地址(如”B52”)或命名区域(如“Interest”);另一种使用整数坐标值,有些情况下使用这种方法是更方便的(特别是当你在代码中有索引号并且想使用它们引用工作表时)。 • SetRange: Same as SetCell, but for setting values into an entire contiguous range. Same two flavors exist. • SetRange:除了为整个相邻区域设置值外,其它与SetCell相同。 • Refresh: Read data from an external data connection (or all of the workbook’s connections) and refresh the values in the relevant cells, e.g. in PivotTable cells or in the results of cube formulas. • Refresh:从外部数据连接(或所有工作薄连接中)读取数据,并且更新相关单元格的值,例如,数据透视表单元格或三维公式的结果。 • Calculate: Recalculate the formulas in a specific range or in the entire workbook. Useful when the workbook author has turned off automatic calculation. Two flavors – using a string or integer coordinates to refer to a range – much like in the Set methods.= • Calculate:重新计算在整个工作薄或指定单元格区域中的公式。用于工作薄作者关闭自动计算功能的情形。两种方法——运用字符串或整数坐标指定单元格区域——与Set方法相同。 • CalculateWorkbook: Calculate the entire workbook, using one of two calculation methods: • CalculateWorkbook:计算整个工作薄,运用下面的两种计算方法之一: o Recalculate: Calculate only formulas that have dependencies that changed (aka “dirty” formulas). o Recalculate:仅计算已发生变化的公式。 o CalculateFull: Calculate all formulas, regardless of dependency changes. o CalculateFull:计算所有的公式,无论是否发生变化。 • GetCell: Get a value out of a cell. The two regular addressing flavors exist. You can either get formatted string values, or the raw binary values. • GetCell:获取某单元格位置值。有两种常用的寻址方式,获取格式字符串值或原二进制值。 • GetRange: Get a set of values out of a contiguous range of cells. Same addressing flavors. • GetRange:获取一组连续单元格区域位置值。采取同样的寻址方式。 • GetWorkbook: Get the entire calculated workbook into your application memory, as a byte array. You can either get the live result, or a snapshot – essentially, a workbook with the layout of the original workbook, with all the original formatting and with up-to-date values – but with all the formulas and external connections stripped, and without the portions of the workbook that were marked not for viewing during publish. More on snapshots in a future post. • GetWorkbook:在应用程序内存中获取整个已经过计算的工作簿,作为一个字节数组。能够获取实时的结果或者屏幕快照——一个带有原先的工作簿页面布局和所有的初始格式以及最新数据值的工作薄——但所有的公式和外部连接除外,并且不带有在发布时没有标记为视图的工作簿部分。在接下来的文章中将有更多关于屏幕快照方面的内容介绍。 • CancelRequest: If your application runs the Excel Web Services session in a separate thread, and wishes to abort a long-running server request (e.g. a long calculation that the user got tired of waiting to) – it can do so by calling this method. • CancelRequest:如果你的应用程序以单线程运行Excel Web Services会话,并希望中止长期运行服务器的请求(例如长时间的计算将使用户疲于等待),那么你就能够调用该方法进行处理。 • CloseWorkbook: Tell the server to close the workbook that it opened for this session, thereby also allowing the server to release all the resources that it maintained for the context of your session. • CloseWorkbook:告诉服务器关闭为会话打开的工作簿,因此,也允许服务器发布为维持会话文本的所有资源。
Error handling 错误处理
Errors are exposed to a developer’s application in three ways: 显示在开发者的应用程序中的错误有三种方式:
1. Excel calculation errors show up just like they do in Excel – as cell error values (e.g. #VALUE!). When you call GetCell or GetRange and ask for formatted values, you’ll get the #-style error string; when you ask for unformatted values, you’ll get an enumerated error code. 2. An error in processing one of the web service methods (which does not enable the method to finish successfully) is exposed as a SOAP exception that your code can catch. 3. Less critical errors, which do not prevent the method from returning normal results, are returned as part of the method arguments (specifically, as an output argument). The reason for this is that an exception would divert the code from its normal execution path, and this is not desirable with these non-critical errors. Checking for them is optional.
1. 计算错误的显示与Excel中一样——当单元格包含错误值时(例如#VALUE!)。当你调用GetCell或GetRange并且要求有格式的值时,你会得到#开头样式的错误字符串;当你要求无格式的值时,你会得到一个枚举错误代码。 2. 处理一个网络服务器方法过程中(不能够使方法成功地完成)的某个错误除了能捕获你的代码外显示为SOAP。 3. 不会阻止方法获得正常的结果的次要错误,其返回值作为方法参数的部分(具体地讲,作为一个输出参数)。原因是将代码从它的正常执行路径转移,这些次要的错误都不可取的。检查这些错误是可选择的。
Sessions 会话
One thing that developers will need to be aware of is the way Excel Calculation Services maintains sessions for performance reasons. A good way to understand the benefit of server state is to think about a user who interacts with an Excel spreadsheet in a web browser. Each time the user takes the next interactive step, e.g. drills down a PivotTable, changes an input parameter, refreshes data connections and so on – we want the server to only compute the difference between what the user saw on the screen before taking the current step, and what they should see as a result of this step. For performance reasons, we do not want the server to read the workbook file from disk again, or to recalculate formulas that do not need recalculation. 开发者需要注意使Excel Calculation Services为了性能而继续会话的方法。一种利于理解服务器状态的方法是考虑用户在网络浏览器中与Excel电子表格交互。每次用户执行下一交互步骤,例如,调整数据透视表、改变输入参数、更新数据连接等——我们希望服务器仅计算不同之处─—执行当前步骤以前用户在屏幕中所看到的,和执行当前步骤后他们将看到的。从性能方面考虑,我们不希望服务器重复从磁盘中读取工作簿,或者在不需要重新计算时重新计算公式。
This is also desirable when an Excel server-side calculation is performed by the server for a custom solution that uses the Excel Web Services. For example, if the solution code sets a cell to a new value, we only want the server to calculate formulas that depend on that cell’s value – and nothing else. So the server keeps the “state”, or context, of a custom application’s calculation in server memory. This context is called a session. In order to let the application tell the server which session it is working with, a session id is used. The server returns this id to the application when it starts a new session (by opening a workbook), and then the application code passes this session id to subsequent web service calls. 通过使用Excel Web Services自定义解决方案执行Excel服务器端计算也是可取的。例如,如果解决方案代码给单元格设置新的值,我们希望服务器仅依靠单元格值去计算公式。因此,服务器保存自定义应用程序计算结果的“状态”或上下文关系在服务器内存中。这个上下文关系被称作会话,使用会话ID让应用程序告诉服务器处理哪个会话。当开始新的会话时(通过打开工作簿),服务器给应用程序返回这个ID,然后应用程序代码通过会话ID调用网络服务器。
What’s next? 下一步的内容
I will review a sample application that provides a specific example of how to use Excel Web Services. 我将介绍一个如何应用Excel Web Services应用程序的详细示例。
Published Thursday, November 17, 2005 9:20 AM by David Gainer
注:本文翻译自http://blogs.msdn.com/excel,原文作者为David Gainer(a Microsoft employee),Excel home授权转载。严禁任何人以任何形式转载,违者必究。
[/Point]
非常感谢Kevin版主的帮助和指导! |