使用c++开发excel插件(第1章 准备知识)

60 篇文章 0 订阅

http://blog.csdn.net/wxy6285/article/details/3255424

我们目前最常见的几个excel的版本是Excel 97/2000/2002/2003/2007,本书提到的所有例子都是在Excel2003环境中的。它们虽然版本不同但是大多数接口并没什么区别。而且我们使用的是excel的开发包,所以只要开发包不变。当然我们这里所有的版本都是指在32-bit的。Excel的开发包可以从微软网站上下载到。下载http://download.microsoft.com/download/platformsdk/sample27/1/NT4/EN-US/Frmwrk32.exe这个文件到本地,它里面包含了将要用到的xlcall.h和xlcall32.lib文件。Xlcall.h中包含了全部的excel中的数据结构类型和C API函数的定义,关于如何使用它们,你可以参考Macrofun.hlp,它里面包含了全部的api函数的描述,在后面的章节中我们会重点的讲到一些常用的API函数,。下载地址http://download.microsoft.com/download/excel97win/utility4/1/WIN98/EN-US/Macrofun.exe

2、认识excel插件(add-ins)

       其实插件在excel中叫做加载宏,是一类程序,它们可以为Excel添加命令扩展其功能。你可以把工作薄保存为加载宏,只需在保存时选择.xla文件格式即可。加载宏业可以用C/C++编写,只要在加入一些和excel衔接的接口就可以在excel中调用了,通常其文件的扩展名为.xll。Excel中也包含一些常用加载宏,在安装时默认安装到Microsoft Office/Office文件夹中的Library文件夹或Addins文件夹。默认这些宏并没有全都加载,你可以通过点击菜单“工具/加载宏”,在弹出的“加载宏”对话框中选中你要加载的宏。主要包含以下几种功能的加载宏:

加载宏

文件名

说明

分析工具库

ANALYS32.XLL

添加金融、统计及工程分析工具和函数。

分析数据库-VBA 函数

ATPVBAEN.XLA

允许开发人员用“分析工具库”的语法发布金融、统计及工程分析工具和函数。

条件求和向导

SUMIF.XLA

创建公式,对区域中满足指定条件的数据进行求和计算。

欧元转换工具

EUROTOOL.XLA

将数值的格式设置为欧元格式,并提供EUROCONVERT 工作表函数用于转换货币。

Internet Assistant VBA

HTML.XLA

开发者可用 Internet Assistant 语法,将Excel 数据发布到网站上。

查阅向导

LOOKUP.XLA

创建一个公式,通过区域中的已知值在区域中查找数据。

“规划求解”加载宏

SOLVER.XLA

对基于可变单元格和条件单元格的假设分析方案进行求解计算。

 

excel中有三种加载宏程序:Excel加载宏,自定义的com加载宏和自动化加载宏。在功能上它们都可以实现你想要的功能,只是在开发方法有些不同。

 

Excel加载宏

自定义的com加载宏

自动加载宏

文件扩展名

.xla或xll

.exe或.dll

.exe、.dll或.ocx

开发工具

VC++或VBA

VC++或VB

VC++或VB

在excel中的操作位置

工具/加载宏

工具/Com加载项

工具/加载宏/自动化

开发难易程度

容易

困难

困难

VBA(Visual Basic Application)是Visual Basic的一个宏语言版本,主要用于扩展Ms Office的功能,你可以在菜单“工具/宏/Visual Basic 编辑器”打开VBA编辑器,并可以直接编写操作office的代码,其语法和Visual Basic基本一样,而且也继承了VB的简单易用的特性。如图1

图1

Excel加载宏是我们这本书主要介绍的对象,在以后的内容中我们会重点介绍它。自定义Com加载宏和自动化加载宏相对复杂一些,暂不作详细介绍


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This book is intended to provide the reader with a guide to the issues involved with creating powerful and reliable add-ins for Excel. With years of use, many people build up the experience and understanding needed to create custom functions for Excel in C and C++. However, given the very limited books and resources available, this can be a largely trial-and-error process. The motivation in writing this book is to create something I wish I had had through the years: a coherent explanation of the relevant technology, what steps to follow, what pitfalls to avoid, and a good reference guide. With these things at your side, writing C/C++ DLL and XLL resources can be almost as easy as writing them in Visual Basic, but yields the enormous performance benefit of compiled C/C++ and the Excel C API. In setting goals for this book, I was particularly inspired by two excellent books that I have grown to admire more and more over the years, as they have repeatedly proven their worth; The C Programming Language (Kernighan and Ritchie) and Numerical Recipes in C (Press, Teukolsky, Vetterling and Flannery), albeit that the style of C-coding of the latter can be somewhat dense. If this book achieves a fraction of the usefulness of either of these then you will, I hope, be happy to own it and I will be happy to have written it. This book is intended for anyone with at least solid C and/or C++ foundation skills, a good working knowledge of Excel, a little experience with VBA (though not necessary) and the need to make Excel do things it doesn’t really want to do, or do them faster, more cleanly, more flexibly. A reasonable grasp of basic software development concepts and techniques is assumed. (Section 1.1 Typographical and code conventions used in this book, on page 1, provides more detail of the coding style of the examples given.) The example add-in project included on the CD ROM is intended to demonstrate some of the most important or difficult concepts described in the book, as well as the possibilities that are opened up when you can really play with Excel. These reflect my professional background in the financial markets, although if you are not of that world, you should still find that the techniques described are very widely applicable. There is an enormous amount of material that could have been included in a book on this subject that has either been pared down to the briefest of coverage or omitted completely. I fully accept that there will be those who, perhaps rightly, feel that certain things should have been covered in a book that boasts such a title, and I can only apologise. Any future editions will, I hope, provide an opportunity to rectify the most heinous and unpopular of these shortcomings.
使用c语言开发Excel插件是一种将程序与Excel表格集成的方式。通过编写C语言代码,我们可以实现在Excel中添加自定义的功能和特性。 首先,我们需要使用C语言的开发工具,例如Microsoft Visual Studio等,来创建一个Excel插件项目。然后,在项目中引入必要的头文件和库文件,以便能够与Excel进行交互。 接下来,我们可以使用C语言的函数和结构体来定义插件的功能。例如,我们可以编写函数来读取和写入Excel表格中的数据,计算表格中的公式,创建和修改工作表等。我们还可以定义自定义的事件处理函数,以响应Excel中的特定操作。 在编写插件的过程中,我们需要关注Excel的对象模型和API,以便正确地操作Excel的各种功能。通过使用Excel提供的函数和接口,我们可以访问和操控Excel的各种对象,例如工作簿、工作表、单元格等。 最后,我们需要将编写好的插件编译成可执行的插件文件,例如动态链接库(DLL),以便能够在Excel中加载和使用。加载插件后,用户可以通过Excel的界面或快捷键等方式去调用插件中的功能。 总之,使用C语言开发Excel插件可以为Excel添加自定义的功能和特性,提升Excel使用效果和用户体验。但需要注意的是,开发插件需要理解Excel的对象模型和API,以及熟悉C语言的开发技巧,确保插件能够正确地与Excel进行交互和操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值