ad

Excel服务VI――用Excel Web Services创建利用程-英雄云拓展知识分享

匿名投稿 307 2024-01-14

译者:fanjy  来源:其他
发表于:2006年7月7日

Excel Services part 6: Building applications with Excel Web Services
Excel Services(第6部份):用Excel Web Services创建利用程序

While talking about scenarios for Excel Services, I mentioned “Reusing the logic encapsulated in Excel spreadsheets in custom applications” – which means accessing spreadsheets and their contents server-side via web services in a way that’s scalable and manageable. I would like to elaborate on this topic over a couple of posts. Today, I will introduce “Excel Web Services”; in a follow-up post I will show how to develop a small sample application using said web services.
在介绍Excel Services 中的方案时,我提到过”在用户自定义内涵程序中重复利用Excel电子表格的逻辑封装”——可升级和管理经过网络服务器访问电子表格和存储信息服务器端。我在上面的一些文章中就这个主题作过详细的介绍。今天,我将介绍“Excel Web Services”,接下来的文章展现如何用网络服务器开发小的利用程序示例。

In a nutshell…
概述

Let’s briefly revisit Excel Services’ architecture. The Excel Calculation Service is the “engine” of Excel Services; it is the component that loads and calculates spreadsheets. In the “interact with the spreadsheet in your browser” scenarios covered in previous posts, Excel Calculation Services loads and calculates a spreadsheet and then hands it off to the Excel Web Access, which is the component that produces the HTML that ends up in your browser. The point of today’s post (and the post that will follow) is that developers can also use Excel Calculation Services without needing to interact with the Excel Web Access. Specifically, we have built a web service API directly on top of the Excel Calculation Services so that developers can call server-side spreadsheets directly from their own applications. For example, developers could write code that opens a spreadsheet on a server, sets cells and ranges to specific values, controls external data refresh and workbook calculation, and finally retrieves values from the calculated workbook (or retrieves the workbook in its entirety). Let’s look at some more specific examples.
先简单地回顾一下Excel Services架构 。Excel Calculation Service是Excel Services的”引擎”,是装载和计算电子表格的组件。在上篇文章中介绍了”在阅读器中与电子表格相交互”, Excel Calculation Service装载和计算电子表格,并且不需要Excel Web Access(配置在阅读器中生成HTML的组件)。这篇文章接下来介绍开发者不需要Excel Web Access的配合也能应用Excel Calculation Service。具体地讲,我们在Excel Calculation Service中已直接创建了一个网络服务器API,以便于开发者能在他们自己的利用程序中直接调用网络服务器真个电子表格。举例来看,开发者能够写用来打开服务器上的电子表格的代码,设置单元格和区域为指定值,控制外部数据更新和工作薄计算,并且最后从已过计算的工作簿中取回数值(或取回全部工作薄)。下面罗列了一些更详细的例子。

What sorts of things are these web services good for?
这些网络服务有哪些功能?

• Excel Web Services enables many interesting scenarios. Here are two examples that we have heard repeatedly from our customers.
Using the logic in Excel spreadsheets in a server application – without the “traditional” need to recode this logic in a programming language. In this scenario, the business expert who authored the spreadsheet can keep maintaining the model in Excel; the administrator can protect that model on the server using the appropriate set of users, roles, permissions, and a firewall; and the developer can call Excel Web Services to incorporate the logic in the spreadsheet into the rest of a custom solution. Another variation on this would be providing custom UI to Excel-based server applications which use Excel Web Services to interact with a server-side calculation session.
Excel Web Service能处理一些有趣的情况。下面有两个常常从我们的客户那里听到的例子。
在服务器利用程序中的电子表格上应用逻辑——不需要使用”传统的”方法,即用编程语言重新编
写这些逻辑代码。在这类情况下,创建电子表格的商务专家能在Excel中保护这个模型;管理员
能在服务器上使用适合的用户权限设置来保护模型;开发者能调用Excel Web Services在用户
解决方案部份加入电子表格逻辑。在这方面的另外一个变化是为基于Excel服务器利用程序提供了
自定义内涵用户界面,该服务器利用程序使用Excel Web Services与服务器端计算进程进行交互。

Excel服务VI――用Excel Web Services创建利用程-英雄云拓展知识分享

• Automating spreadsheet updates on servers. This works especially well in combination with the new Open XML file format, which greatly simplifies the task of programmatically creating an Excel file from scratch or using a template. Once the new file has been created, it often needs to be calculated – for example, if there are external data feeds that need to be updated. It is straightforward for developers to write code to use Excel Web Services to do all of this, then retrieve an up-to-date copy of the calculated file and save it back to the server, or deliver it to any other destination.
在服务器中自动更新电子表格。这项功能相当好地组合在崭新Open XML文件格式中,可非常简单地自动编程完成从稿纸或模板创建一个Excel文件的任务。一旦创建了这个新文件,就常常需要计算它——举例来看,如果有需要更新的外部数据,开发者可以直接写代码去指令Excel Web Services完成所有这些工作,然后取回这个已过计算的文件副本并存储在服务器上,或将它传送到另外一个目标上。

What specifically can the web service do?
网络服务用具体处理甚么工作?

Here is the summary: your code can start a session with the Excel Calculation Service, set values into cells and ranges, process the workbook, and get calculated values or the entire workbook back into your application.
大致地讲:你的代码能够开始与Excel Calculation Service进行会话,设置单元格和区域的值,处理工作薄,取得计算结果或全部工作薄并反馈到你的利用程序。

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:从外部数据连接(或所有工作薄连接中)读取数据,并且更新相干单元格的值,举例来看,数据透视表单元格或3维公式的结果。

• 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:计算全部工作薄,应用下面的两类计算方法之一:

• Recalculate: Calculate only formulas that have dependencies that changed (aka “dirty” formulas).
• Recalculate:仅计算已产生变化的公式。

• CalculateFull: Calculate all formulas, regardless of dependency changes.
• 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:获得某单元格位置值。有两类经常使用的寻址方式,获得格式字符串值或原2进制值。

• 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:
显示在开发者的利用程序中的毛病有3种方式:

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

注:本文翻译自其他,原文作者为David Gainer(a Microsoft employee)。

非常感谢Kevin版主的帮助和指点!


选择英雄云云表单=选择更智能的Excel

在现代企业管理中,数据的高效管理和处理至关重要。随着信息技术的不断发展,英雄云云表单已经成为了提高数据录入、管理和分析效率的不可或缺的工具。让我们来深入探讨英雄云-云表单的几大优势。

基础字段:多样性满足业务需求

英雄云云表单中包括了各种基础字段,如单行文本多行文本数字输入框单选框复选框下拉框下拉复选框日期时间分割线等。这些字段的多样性使用户可以根据具体的业务需求,轻松进行文本、数据和时间信息的录入或修改。例如,您可以使用单行文本字段录入员工姓名、产品型号等,或者使用下拉框进行多选,根据不同情况选择更加方便的字段类型。

高级字段:提升工作效率

英雄云云表单还提供了高级字段,如地址图片附件手写签名手机子表关联数据关联查询以及流水号。这些高级字段在基础字段的基础上升级,可帮助用户完成一些琐碎的工作。例如,使用地址字段可以避免逐字打字,而流水号字段可以自动生成规律性的编号,非常适用于合同编号生成等场景。

部门成员字段:精确管理与通讯录的关联

英雄云的部门成员字段允许企业对各个部门的成员进行精确管理。用户可以通过部门成员字段获取通讯录中的部门成员信息,应用于记录报销人、报销部门等场景。这些成员字段还细分为成员单选成员多选,可根据具体需求在通讯录中选择一个或多个成员。

聚合表:数据处理更智能

英雄云聚合表功能用于对已存在的表单数据进行聚合计算,从而得到一张聚合表,后续其他表单可调用聚合表进行数据联动、关联查询和关联数据等操作完成数据处理。这一功能可应用于多种场景,如进销存管理、财务管理和门店零售管理等,帮助企业完成数据处理,提高工作效率。

表单权限设置:灵活管理数据访问

英雄云的表单权限设置允许用户根据企业的具体需求管理表单的访问和操作权限。用户可以根据系统权限或自定义权限对不同成员或团队进行权限设置,以确保数据的安全和合规性。这一功能使企业能够根据变化的业务需求和团队结构,实时调整权限设置。

自定义打印模板:文档输出更便捷

英雄云云表单支持自定义打印模板,可将表单数据转换为可打印的Word文档。用户可以根据自己的需求进行排版和编辑,将产品规格说明书等文档轻松生成。这一功能提供了一种标准化的文档输出方式,简化了信息整理的过程。

综合来看,选择英雄云云表单意味着选择更智能、更灵活、更高效的数据管理工具。无论是提高工作效率,精确管理数据,还是实现数据处理,英雄云云表单都能满足您的多样化需求,助力您的业务发展。

如果您正在寻找一款强大的云表单工具,不妨考虑英雄云,它将为您带来更多的便捷和智能,助您事半功倍。


免责声明:

本网址(www.yingxiongyun.com)发布的材料主要源于独立创作和网友匿名投稿。此处提供的所有信息仅供参考之用。我们致力于提供准确且可信的信息,但不对材料的完整性或真实性作出任何保证。用户应自行验证相关信息的正确性,并对其决策承担全部责任。对于由于信息的错误、不准确或遗漏所造成的任何损失,本网址不承担任何法律责任。本网站所展示的所有内容,如文字、图像、标志、音频、视频、软件和程序等的版权均属于原创作者。如果任何组织或个人认为网站内容可能侵犯其知识产权,或包含不准确之处,请即刻联系我们进行相应处理。

上一篇:Excel数据排序方法大集锦-英雄云拓展知识分享
下一篇:VLOOKUP出错?排查手册请收好-英雄云拓展知识分享
相关文章

 发表评论

暂时没有评论,来抢沙发吧~

×