ad

Excel2007的自定义内涵工作表函数(第一部份)-英雄云拓展知识分享

匿名投稿 254 2024-01-14

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

Excel 2007 investments in UDFs #1
EXCEL 2007的自定义内涵工作表函数(第一部份)

For the next few posts, we have a “guest post” from Danny Khen, a program manager on the Excel Services team.  Danny is going to talk about UDFs in Excel and Excel Services.  Enjoy.
在接下来的几个帖子中,Excel Services团队的项目经理Danny Khen将讲述Excel和Excel Services中的自定义内涵工作表函数,希望大家喜欢。

UDFs are user-defined worksheet functions – custom functions that you create to supplement Excel’s set of intrinsic worksheet functions. UDFs are used to create calculation libraries, or to import data into Excel sheets in custom ways.
UDF就是自定义内涵工作表函数的缩写,就是用户创建的用于满足特定需求的函数,它是Excel内置工作表函数的一个补充,UDF可以用于生成一个计算库或依照用户定义内涵的方式将数据导入Excel工作表。

In Excel 2007, we’ve made a number of key investments around UDFs. They revolve around two main areas: allowing UDFs to take advantage of important Excel improvements, and extending UDF-based Excel solutions to the server side with Excel Services.
在Excel 2007中,我们围绕UDF花费了很多精力,主要有两个方面:Excel的重大改进可以利用于UDF和利用Excel Services将基于UDF的Excel解决方案扩大到服务器端。

Updated XLLs
更新XLLs

A while back Dave mentioned that we updated XLLs (Excel’s addins based on the C-API) to give developers access to new Excel functionality. As that post explained, one of the common things that developers do in XLLs is to implement UDFs. We wanted to make sure that XLL authors can make use of some great new features of Excel 2007 itself in the UDFs they create. To recap, XLLs have support in Excel 2007 for:
正如Dave前面提到的一样,我们更新XLLs(基于C-API的Excel加载宏)以便于开发者使用Excel的新功能,对开发者来讲,在XLLs中实现UDF成为一件很普通的事情,我们希望确保XLL作者可以在UDF中使用Excel2007那些伟大的新功能,简单的说,Excel 2007 XLLs支持:

Excel2007的自定义内涵工作表函数(第一部份)-英雄云拓展知识分享

The bigger grid
更大的数据表

More function arguments
更多的函数参数

Multi-threaded calculation
多线程计算

There are many more detailed about those improvements in that other post.
在另外的帖子中会更加详细的解释这个改进。

Server-side UDFs
服务器真个UDF

Dave has also posted a number of entries about Excel Services – the new feature in the Office SharePoint Server 2007 that enables calculation, display, and exploration of Excel workbooks on the server. These posts cover many aspects of Excel Services.
Dave已发表了好几个关于Excel Services的帖子,这些帖子涵盖了很多Excel Services的概念,简单的说就是: Office SharePoint Server 2007 提供的新功能,可以在服务器上实现计算、显示和访问Excel工作簿。

Much like Excel’s ability to be extended by writing UDFs in Excel addins, Excel Services also has an extensibility mechanism for writing UDFs. I’d like to use the rest of this post to explain and demonstrate Excel Services UDFs. In a follow-up couple of posts, I will show how you can create Excel solutions that use UDFs and can run both on a client machine using Excel 2007 and in a server environment using Excel Services.
就像可以经过在Excel加载宏中使用UDF扩大Excel功能一样,Excel Services一样可使用UDF的扩大机制,我希望利用下面的帖子来解释和演示Excel Services UDF, 在接下来的几个帖子中,我将向大家展现如何利用UDF实现Excel解决方案,此方案不但可以用于Excel 2007的客户端,而且可以用于具有Excel Services环境的服务器。

They’re managed
托管代码

Server-side UDFs are implemented as methods .NET 2.0 assemblies. That is to say, Excel Services directly supports only managed code UDFs. Existing native function libraries and Excel UDFs can be used with Excel Services by “wrapping” them with the new style of server managed UDFs; I will show how in the follow-up posts.
服务器真个UDF利用了.NET 2.0组件,也就是说Excel Services可以而且仅仅支持托管代码UDF,已在用的函数库和Excel UDF可以在服务器端托管UDF中共存,在下面的帖子中将进行介绍。

But why did we actually “go managed”? Excellent question. Managed code for enterprise-level solutions is becoming more and more popular, because of the many advantages that .NET code has to offer. Robustness and security are among the important advantages. Some of you may already be engaged in developing managed UDFs or other types of managed solutions. With Excel Services, we focused specifically on server stability, and we felt that using .NET as the basis for our extensibility would be the right thing to do in this respect.
为何要使用托管代码呢?这是一个非常好的问题,托管代码在企业级解决方案中愈来愈广泛的利用,缘由在于.NET代码有很多优点,硬朗和安全是其中最重要的优点,你们中某些人可以已投入托管UDF或提供托管方案的开发当中,对Excel Service我特别关心服务器的稳定性,因此我们觉得以.NET为基础进行扩大是完全正确的。

They’re part of a V1 feature
他们将成为V1功能的一部份

In Office SharePoint Server 2007 we introduce the first implementation of Excel Services and of its extensibility mechanism. To start with, we simply had to prioritize the support for various features in Excel Services (even regardless of UDFs), and not everything made it for this first version. Moreover, we know that going forward we will be doing a lot of thinking around managed interfaces and extensibility for Excel – both on the client side and on the server. We want to make sure that customers’ initial investment in managed UDFs is secured, and that at the same time we are not constrained in any way when we design the best possible infrastructure in the future. For those reasons, there are certain restrictions with the first version of server UDFs:
在Office SharePoint Server 2007中我们第一次引入了Excel Services和扩大机制,开始时,我们不能不对Excel Services的各种功能(即便疏忽UDF)进行逐一处理,因此并不是所有的功能都会在第一个版本中提供,另外,我们深知不管是客户端还是服务器端,都有非常多的关于托管接口和Excel扩大的事情等着我们去做,我们希望尽可能保护用户托管UDF的投资,同时也希望我们在将来可能设计出的更好的架构,不会过量的作用现在的客户,鉴于上面的缘由,在初版服务器UDF中会有某些限制。

No Excel OM: the entire interface with the Excel sheet is done thru the UDF call signature; arguments are passed into the function from the Excel formula, and return values are passed back into the formula.
Excel工作表的接口全部经过UDF调用标识,参数由Excel公式传递到函数,返回值传回公式。

More restrictive than Excel addins with
与Excel加载宏相比有更多的限制:

Type conversion and supported data types.
类型转换和所支持的数据类型

Error handling: all exceptions thrown by the UDF code are returned into the Excel sheet as #VALUE errors.
毛病处理:所有的UDF代码的异常反应在Excel工作表中都是#VALUE毛病。

Simple load / runtime behavior: for example, all UDFs currently run together with Excel Services code in the same .NET application domain.
简单的装载/运行:举例来看,现在所以的在Excel Services代码中的UDF存在于同一个.NET利用域中。

We believe that lots of useful solutions can be created under these restrictions; in fact we see many existing Excel UDF-based solutions that could comply.
我们详细基于这些限制可以产生很多有用的解决方案,事实上我们可以看到很多现存的基于UDF的Excel解决方案可以鉴戒。

They need to be thread-safe
安全线程

Excel Services is a server feature, and its calculation engine runs as a multi-threaded backend service. We have to require (and assume) that all UDFs are thread safe.
Excel Services是服务器功能,它的计算引擎提供多线程后台服务,我们不能不要求所有的UDF都是可靠的线程

Security
安全

A couple of things to mention about the way a server administrator can control the security of Excel Services UDFs.
服务器管理员可以从以下几个方面控制Excel Services UDF的安全性。

First, Excel Services will not load and run just any old method in any old .NET assembly. An admin needs to register the assembly on a server list of trusted UDF assemblies.
首先,Excel Services将不会装载和运行任何存在于之前.NET组件中的旧的方法,管理员需要在服务器上注册信任的UDF组件。

On top of that, since these are .NET assemblies, an admin can make use of .NET’s CAS (Code Access Security) infrastructure to restrict UDF access to resources. For example, if a UDF package is simply a collection of math calculation functions, an admin can turn off its ability to access web services, external data, native code etc – and make the server environment safer for everyone.
其次,由于使用了.NET组件,所以管理员可以利用.NET’s CAS (代码访问安全) 限制UDF访问资源,例如:对一个简单的数学计算函数的UDF包,管理员可以制止它使用网络服务,外部数据,原始代码等功能,使得服务器环境对每一个人都更安全。

So what does this thing look like?
UDF的真面目

Very simple, actually. All you need to know about (assuming you speak some .NET dialect) is two new attributes. Both of them are defined in the Microsoft.Office.Excel.Server.Udf namespace, and you need to reference an assembly that is shipped with Excel Services (Microsoft.Office.Excel.Server.Udf.dll) to get them.
实际上很简单,你所要知道的只有两个新的属性,它们都要在Microsoft.Office.Excel.Server.Udf名称空间中定义内涵,你可以参考Excel Services (Microsoft.Office.Excel.Server.Udf.dll)附带的组件。

The two attributes are UdfClass, which you use to mark a class where server UDFs are defined, and UdfMethod, with which you mark each individual public method to be considered a server UDF. The UdfMethod also has a boolean property – IsVolatile – used to declare the UDF as volatile, if you want the server to call it each time it recalculates the workbook, regardless of any change in its dependencies. The default is false, which means that the method is non-volatile; it gets called only when a value changes somewhere down the dependency chain of the formula that calls the UDF.
这两个属性是UdfClass(用于标识服务器UDF定义内涵的类)和UdfMethod(用于标识每一个共用的方法都是一个服务器UDF),UdfMethod也有一个布尔类型属性-IsVolatile-用于声明UDF具有易失性,如果你希望服务器每次调用时,不论是否有改变工作簿都会重新计算,就要设置此参数为True,该参数的默许值为False,也就是说该方法是非易失性的,在这类情况下,只有与公式相干的改变才会调用UDF.

That’s really it. A typical UDF class will look something like this:
一个典型的UDF类就像下面所示:

//Code
using Microsoft.Office.Excel.Server.Udf;

namespace YourNamespace
{
    [UdfClass]
    public class YourClass
    {
        [UdfMethod]
        public <return-type> NonVolatileMethod(<arguments>)
        {
  …
        }
        [UdfMethod(IsVolatile=true)]
        public <return-type> VolatileMethod(<arguments>)
        {
  …
        }
    }
}

Show us the goods!

Well, alright… Attached to this blog post is a fully developed code sample. It shows a UDF package by the name of WishExcelHad (because it implements a couple of functions that we wish Excel had…). The package has two method to manipulate text strings with words. The first method, WehWordM, takes the string, a required word position, and a delimiter string, and returns the word in that position after parsing the text with the given delimiter. The other method, WehWordcountM, takes a string and a delimiter, and returns the number of words in that string, when it is parsed with the given delimiter.
博客帖子中的代码是一个完全的开发代码示例,其名称为WishExcelHad的UDF包,这个UDF保有两类使用文本字符串的方法,第一种方法,利用WehWordM,获得字符串、单词位置和分隔符,针对指定的分隔符返回分析的文本;另外一种方法,利用WehWordcountM,获得字符串和分隔符,针对指定的分隔分析并返回该字符串中的单词个数。

You can use the attached Excel workbook as an example that calls these two methods in formulas. You’ll need to save it to Excel Services as an XLSX file.
你可以用附带的Excel工作簿为例子在公式中调用这两个方法,并以XLSX文件保存到Excel Services中。

Why the weird “M” as the suffix for those method names? It designates “Managed” – these UDFs are implemented purely with managed code, and are intended to run with Excel Services. Stay tuned to the blog and look for the following posts, where I will show versions of the same UDFs, that can run across Excel 2007 and Excel Services.
为何我们用“M”作为这些方法的名字的前缀呢?它代表“托管”-这些UDF完全有托管代码实现,将利用于Excel Service,在接下来的帖子中,我将向大家展现UDF的不同版本可以分别运行在Excel 2007和Excel Services中。

Published Wednesday, May 03, 2006 6:14 AM by David Gainer
Filed Under: Excel Server, UDFs, Programmability

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


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

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

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

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

高级字段:提升工作效率

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

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

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

聚合表:数据处理更智能

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

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

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

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

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

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

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


免责声明:

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

上一篇:按任意字段将总表拆分为多个分表-英雄云拓展知识分享
下一篇:Excel服务VIII――控制和保护数据表-英雄云拓展知识分享
相关文章

 发表评论

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

×