关于XLL加载项动态加载、卸载的演示及XLL函数自定义类型注册的演示
1、在XLL中,把函数定义成不同的类型,在Excel中的实际效果也不同,具体如下:
pxMacroType value 0 1 2
Can be called from a worksheet Yes Yes No
Can be called from a macro sheet Yes Yes Yes
Can be called from a defined name definition Yes Yes Yes
Can be called from a conditional format expression Yes Yes No
Listed in the Function Wizard for worksheet functions No Yes No
Listed in the Function Wizard for macro sheet functions No Yes Yes
注册函数需要使用Excel4的xlfRegister参数,其参数说明如下:
pxModuleText XLL名字,可以通过xlGetName获取
pxProcedure 推荐使用字符串,表示在XLL 代码中的函数名
pxTypeText 表示函数参数的类型和函数返回值的类型,字符串
pxFunctionText 函数名,在Excel中显示的名称
pxArgumentText 参数描述字符串
pxMacroType 函数类型: 0,1,2
pxCategory 函数类别
pxShortcutText 命令(类型2)的快捷键,"A" assigns this command to CONTROL+SHIFT+A
pxHelpTopic 帮助的引用字符串
pxFunctionHelp 函数向导中的描述
pxArgumentHelp1 函数参数1描述,后面依次类推
为了直观看到不同函数类型的效果,我用ExcelDna做了个演示文件,在文件中实现了XLL的加载、卸载;函数的注册、反注册等功能。
由于ExcelDna的限制,直接使用xlfRegister更改函数类型,会造成返回值的错误。因此,例子中的MySub函数返回值无意义。


工作表函数向导 宏表函数向导
2、XLL可以通过另一个XLL进行加载和卸载,在Excel开发里面,这是最方便的升级方式。把俺的DNATool.XLL放到同一目录下,通过加载项里面的菜单可以加载。注意名字必须完全一致,俺的代码只认识这个名字 :)

文件下载 TestXllFunction
有什么建议欢迎联系QQ:564955427
************************************************
Conditional Formatting Formulas Must Have References - If you have a conditional formatting formula that references a UDF defined in another workbook such as an add-in, then you must add a Reference to that workbook before you can reliably use the functions defined in it. If you don't, you will (sometimes) get the error 'This type of reference cannot be used in a Conditional Formatting Formula'. To add a reference, press Alt+F11 to go to the code editor, then go to Tools, References, and add the reference to this workbook by project name for the project containing the VBA code you need.
条件格式里面只能使用工作簿本身的公式,或者在VBE中引用的xla、xlsm等文件里面的公式。加载宏即使已经加载,但没有引用的话,依然不能在条件格式的公式里面使用。
************************************************
http://msdn.microsoft.com/en-us/library/bb687858.aspx Accessing XLL Code in Excel
Calling XLL Functions Directly from Excel
Once they are registered, XLL worksheet and macro sheet functions can be called from anywhere a built-in function can be called from:
A single-cell or array formula on a worksheet.
A single-cell or array formula on a macro sheet.
The definition of a defined name.
The condition and limit fields in a conditional format dialog box.
From another add-in via the C API function xlUDF.
From Visual Basic for Applications (VBA) via the Application.Run method.
You can obtain a reference to the calling cell or range of cells within your function using the C API function xlfCaller. If the function was called from the cell’s conditional format expression, you are still returned a reference to the associated cell or cells, so you cannot assume that the cell’s formula contains the XLL function. If your function was called from a VBA user-defined function (UDF), xlfCaller again returns the address of the cells that called the VBA function. For more information, see xlfCaller.
Registering Functions and Commands with Excel
Registration tells Excel the following about a DLL entry point:
Whether it is hidden or, if a function, whether it is visible in the Function Wizard.
Whether it is callable only from an XLM macro sheet, or also from a worksheet.
If a command, whether it is a worksheet function or a macro sheet equivalent function.
What its XLL/DLL export name is, and what name you want Excel to use.
If it is a function:
What data types it returns and takes as arguments.
Whether it returns its result by modifying an argument in place.
Whether it is volatile.
Whether it is thread safe (supported starting in Excel 2007).
What text the Paste Function Wizard and AutoComplete editor should display to help with calling the function.
Which function category it should be listed under.
This is all achieved using the C API function xlfRegister, equivalent to the XLM function REGISTER.
关于XLL加载项动态加载、卸载的演示及XLL函数自定义类型注册的演示的更多相关文章
- 动态库DLL加载方式-静态加载和动态加载
静态加载: 如果你有a.dll和a.lib,两个文件都有的话可以用静态加载的方式: message函数的声明你应该知道吧,把它的声明和下面的语句写到一个头文件中 #pragma comment(lib ...
- JAVA反射机制--静态加载与动态加载
Java反射是Java被视为动态(或准动态)语言的一个关键性质.这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如pu ...
- Lodop 动态加载模板,动态加载数据
最近需要使用Lodop打印控件,所以就研究了一下,期间从网上找了诸多的东西,基本全是对HTML进行打印的,没有找到我想要的,就只好自己动手丰衣足食. 这篇文章主要讲述的是Lodop与数据的结合使用,官 ...
- JAVA类的静态加载和动态加载以及NoClassDefFoundError和ClassNotFoundException
我们都知道Java初始化一个类的时候可以用new 操作符来初始化, 也可通过Class.forName()的方式来得到一个Class类型的实例,然后通过这个Class类型的实例的newInstance ...
- 使用js加载器动态加载外部Javascript文件
原文:http://www.cnblogs.com/xdp-gacl/p/3927417.html 今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js var ...
- 动态链接库dll的 静态加载 与 动态加载
dll 两种链接方式 : 动态链接和静态链接(链接亦称加载) 动态链接是指在生成可执行文件时不将所有程序用到的函数链接到一个文件,因为有许多函数在操作系统带的dll文件中,当程序运行时直接从操作系统 ...
- JavaScript学习总结(十九)——使用js加载器动态加载外部Javascript文件
今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js 1 var MiniSite=new Object(); 2 /** 3 * 判断浏览器 4 */ 5 M ...
- 使用js加载器动态加载外部js、css文件
let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...
- 建立WIN32 DLL,并使用静态加载和动态加载
新建工程,选择win32 dll 编写.cpp(或.c) MyDll.cpp #include "windows.h" BOOL APIENTRY DllMain(HANDLE h ...
随机推荐
- ELK环境配置+log4j日志记录
ELK环境配置+log4j日志记录 1. 背景介绍 在大数据时代,日志记录和管理变得尤为重要. 以往的文件记录日志的形式,既查询起来又不方便,又造成日志在服务器上分散存储,管理起来相当麻烦, 想根据一 ...
- SQL Server的实例恢复解析
同Oracle一样,SQL Server在非一致性关闭的时候也会进行实例恢复(Instance Recovery),本文根据stack overflow的文章介绍一些SQL Server实例恢复的知识 ...
- php获取ip地址所在的地理位置的实现
1,通过腾讯或者新浪提供的接口来获取(新浪和腾讯类似) <?php function getIPLocation($queryIP){ $url = 'http://ip.qq ...
- Servlet(一):Hello Servlet
今天介绍的专题是servlet和jsp,属于web开发中的基础,先来实际操作一下servlet,创建你的第一个web小项目. 1.新建一个maven项目. 鼠标右键单击eclipse左边项目栏的空白区 ...
- 《Java大学教程》—第22章 多线程程序
22.2 进程(process):P551时间切片(time-slicing):处理器只是完成了一个任务的一部分工作,然后完成下一个任务的一部分工作,因为处理吕每次完成工作的时间都非常短,因此看起来这 ...
- [docker][win10]安装的坑
右键这个小图标,先signin,注意这里是ID 不是邮箱 image.png 可能starting 时候就报错说 “Containers feature is not enabled” 或者 ...
- (转)Spring Boot(七):Mybatis 多数据源最简解决方案
http://www.ityouknow.com/springboot/2016/11/25/spring-boot-multi-mybatis.html 说起多数据源,一般都来解决那些问题呢,主从模 ...
- Openstack安装Dashboard之后,浏览器无法打开页面 500 Internal Server Error
在手动部署Openstack时,按照官方文档安装Dashboard,并进行了配置后,发现用浏览器无法打开界面 页面显示: Internal Server Error The server encoun ...
- 【转】OS X Base System 上没有足够的空间来进行安装
今天在windows环境下安装IOS虚拟机,安装过程中报了一个错:“OS X Base System ”上没有足够的空间来进行安装.如图: 之后的解决办法是:点击上方的[实用工具]->[磁盘工具 ...
- 第1章 Linux内核简介
1.1 Unix的历史 unix的优点 简介,没有繁冗的系统调用 所有东西都被当成了文件对待,对文件和对设备的操作是通过同样的系统调用的接口实现的 内核和相关工具使用C编写,具有很高的可移至性 创建新 ...