在 Visual Basic 中使用 Excel 对象库的脆弱性
一点前言:这个项目虽然在技术上是家庭作业,但完全在我的 5 人团队的控制之下。我们提出了这个项目,定义了范围,并进行了全面的创意控制。所以它不是传统的作业,它相当于一个高级项目。
我正在开发的系统的输出之一应该与格式良好的 Excel 电子表格非常相似。我们可以创建(或查找)一个图形库并用我们自己的代码处理打印......但最终我们认为 Excel 电子表格文件将更便携。由于用户可以在 Excel 中打开它、对其进行编辑、通过电子邮件发送等。
以编程方式访问 Excel 似乎很简单(即: http://support.microsoft.com/kb/302094)
但我的问题是:当“Office 2013”出现并且用户删除Office 2010并安装2013时会发生什么?
我不会维护这个项目...而且我不想强迫别人打开我的代码只是为了引用 Excel 13.0 COM。
我将使用 API 的令人难以置信的基本功能。 只要我可以读写一系列单元格,并调整单元格的内部颜色,我的代码就可以工作。
一般来说,如何让我的 VB.Net 代码访问目标系统上可用的任何 Microsoft Excel API? (包括未来的 Excel API。)
A bit of preface: this project, while technically homework, is completely under my 5-man team's control. We came up with the project, defined the scope, and exercise full creative control. So it's not traditional homework, it's equivalent to a senior project.
One of the outputs of the system I'm developing should be very similar to a well formatted Excel spreadsheet. We could create (or find) a graphics library and handle the printing in our own code... but ultimately we feel that an Excel spreadsheet file will be more portable. As the user can open it up in Excel, edit it, e-mail it, etc.
Accessing Excel programatically seems simple enough (i.e: http://support.microsoft.com/kb/302094)
But my question is: what happens when "Office 2013" comes out, and the user removes Office 2010 and installs 2013?
I won't be around to maintain this project... and I'd hate to force someone into opening up my code just to reference the Excel 13.0 COM.
I'll be using incredibly basic functions of the API.
So long as I can read-and-write to a range of cells, and adjust the interior color of cells, my code will work.
In general, how can I make my VB.Net code access whatever Microsoft Excel API is available on the target system? (Including future Excel APIs.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议首先使用 Excel PIA(主互操作程序集)进行开发,以便您在 Visual Studio 中获得自动完成和在线帮助。
程序完成后,我建议在发布之前切换到后期绑定,以便您的 EXE 可以与不同版本的 Excel 配合使用。
想要(Google“Excel PIA”下载程序集)
Option Strict Off
添加到使用 Excel 对象的模块的顶部Object< /code> 例如
Dim xls As Excel.Application
成为
Dim xls As Object
xls = 新Excel。应用程序
使用
xls = CreateObject("Excel.Application")
I recommend first developing using the Excel PIA (Primary Interop Assemblies) so you get autocomplete and online help in Visual Studio.
Once your program is complete, I recommend switching to late-binding before publishing, so your EXE works with different versions of Excel.
want (Google "Excel PIA" to download the assemblies)
Option Strict Off
to the top of the modules that use Excel objectsObject
e.g.Dim xls As Excel.Application
becomes
Dim xls As Object
xls = New Excel.Application
with
xls = CreateObject("Excel.Application")