Excel自动化功能的问题

发布于 2024-08-12 08:33:08 字数 902 浏览 1 评论 0原文

我正在使用 MS Visual Studio 2008 在 VB.NET 中编写一个与自动化插件相结合的 vsto 插件。 自动化插件在 Excel 中激活并在系统中注册。 调用函数时,自动化插件运行得很好

基本上,当您使用"=(;;...;)"

通过将其写入 Excel 单元格或使用函数向导。

vsto 加载项用于通过命令栏按钮启动 Windows 窗体,用户可以在其中键入所需的参数。如果用户完成,将在构建的单元格中写入一个字符串,看起来就像上面写的示例一样。

我正在解决的问题是,当用户启动excel时,只需使用windows表单生成字符串并单击“确定”用它填充单元格,excel就会尝试找到“=”中的函数原因细胞,但没有找到它。 在单元格中最后出现了 Name?,因为在查看函数向导列表后,我注册的函数消失了。(顺便说一句,该加载项仍然列在“extra->add-ins”下,并且是也会在下一次 excelstart 后再次加载)

但另一方面,如果用户首先使用函数向导来获取函数的值,则在单元格中手动键入它,甚至只是打开函数向导并在打开后直接关闭它而不使用函数,我的 Windows 表单生成的字符串确实有效。

onButtonClick 事件执行以下示例代码:

Me.Application.ActiveCell.Value = "=FUNCTION(""value1"";""value2"")"

所以现在我的问题是,为什么当用户最初使用字符串生成器时,自动化功能会消失吗?

一些建议甚至解决我的问题会非常好。

问候马丁

i´m programming a vsto add-in combined with an automation add-in in VB.NET using MS Visual Studio 2008.
The automation add-in is activated in excel and registered at the system. basically the automation add-in running very well, when you call the function with

"=<function-name>(<argument1>;<argument2>;...;<argument-n>)"

by writing it into an excel cell or using the functionwizard.

The vsto add-in is used to initiate over a commandbarbutton a windows-form, where the user can type the arguments, which are required. If the user has finished a string will be written in the cell builded and looking like the example is wrote above.

the problem i´m fighting with is when the user starts excel, just using the windows-form to generate the string and clicking "ok" to fill the cell with it, excel tries to find the function cause of the "=" in the cell, but dont find it.
In the cell finally stands Name?, because after looking in the functionwizard-list, my registered function disapeared.(Btw the add-in is still listed under "extra->add-ins" and is also loaded again after the next excelstart)

But on the other way if the user first use the functionwizard to get the value of the function, types it per hand in the cell or even just open the functionwizard and close it directly after opening without using the function, my windows-form generated string does work.

The onButtonClick-event performs the following example-code:

Me.Application.ActiveCell.Value = "=FUNCTION(""value1"";""value2"")"

so now my question is, why is the automation function disapearing when the user just use the string-generator at first?

Some advices or even the solution the my problem would be very nice.

Greetings Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-08-19 08:33:08

好吧,

经过一周的搜索和测试其他代码没有成功,我自己找到了问题的原因。我不知道为什么Excel将该函数从列表中踢出,但以下解释确实解决了问题。

我在尝试通过代码调用该函数时犯了两个错误。首先是我选择了错误的写入单元格的方法......只需使用“me.application.activecell.formula”。

第二个也是最重要的原因是真正的原因,整个事情没有成功。通过尝试在一个字符串上设置每个参数、分号、括号等,Excel 以计算模式读取该字符串,当它遇到公式中的分号时,就会出现错误。这导致了一个异常(HRESULT:0x800A03EC),表示刚刚发生了故障。

excel 此时误读了分号并引发异常。偶然我找到了在公式中设置分号来分隔参数的解决方案。您只需在代码中写入“”、“”,而不是“;”。

如果我的解决方案可以帮助其他遇到同样问题的开发人员,我很高兴。

问候马丁

alright,

after one week of searching and testing of other code without success, i found the reason of my problem by my own. i don´t know why excel kicks the function out of the list, but the following explanation will did solve the problem.

I did 2 mistakes trying to call the function by code. the first is that i choosed the wrong method of writing into the cell...just use "me.application.activecell.formula".

the second and most important reason is the real cause, the whole thing didn`t work. By trying to set every argument,semicolon, brackets etc. over one string excel reads the string in calculation mode and is making something wrong when it hits at the semicolon in the formula. this caused a comexception (HRESULT: 0x800A03EC) saying that just a failure occured.

excel missreads the semicolon at this point an throws an exception. by accident i found the solution to set the semicolon into the formula to separate the parameters. you just have to write " "," " into the code instead of " ; ".

i´m happy if my solution could help other developer having the same problem.

greetings martin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文