VB - Visual Studio 2010 中的自动化 Excel - 选择更改问题

发布于 2024-09-30 18:31:38 字数 482 浏览 4 评论 0原文

我目前正在编写一个实用程序,它从 Excel 文档中获取两组不同的数据并将其发送到两个不同的 Web 服务。每组数据都有其自己的按钮,用于将数据发送到 Web 服务。单击 a 按钮后,相应的 Web 服务就会根据输入值返回数据。

我想做的是让这个实用程序可以被广泛的人分发和使用。他们要做的是将他们自己的 Excel 文档的特定单元格同步到我的实用程序中的相应单元格。使用简单的 Excel 公式。例如:

c:\temp\[book1.xls]sheet1'!a1

现在我想做的是,当用户将其单元格链接到我的实用程序上相应的单元格时,自动“单击”我的实用程序上的按钮或更新。

我已经尝试过我的页面上的选择更改事件。但直到我的实用程序处于活动状态或单击后,它才会真正进行处理。

有没有办法让我的实用程序自动更新?如果在我的公用事业关闭时以某种方式做到这一点,那就特别棒了。因此,当用户打开它时,它已经填充了他们的信息,并且输出是正确的。

I am currently writing an utility that takes two different sets of data from an excel document and sends it to two different web services. Each set of data has it's own button that sends the data to the web service. When the a button is clicked, the corresponding web service then returns data depending on the input values.

What I am trying to do is so that this utility can be distrobuted and used by a wide variety of people. What they are going to do is they are going to be synchronizing there particular cells of their own excel document to the corresponding cell in my utility. Using simple excel formulas. For example:

c:\temp\[book1.xls]sheet1'!a1

Now what I am trying to do is automatically "click" the button, or update, on my utility when the user links their cell to its corresponding cell on my utility.

I have tried the selection change event on my page. But it doesn't actually process until my utility is active, or clicked on.

Is there a way to make my utility automatically update? It would be especially awesome if somehow it did this while my utility was closed. So when the user opens it it is already filled with their information, and the outputs are correct.

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

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

发布评论

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

评论(1

两仪 2024-10-07 18:31:38

要求:
您需要保证当用户使用 Excel 时您的应用程序可以收集数据。您的应用程序当时可能未运行。您需要 Worksheet_SelectionChange() 事件自动触发,而不仅仅是在您的应用程序处于活动状态时。

解决方案:
基本上是为了保证 Worksheet_SelectionChange() 始终运行,并且为了保证每当用户打开 Excel 实例时,您都能够收集和处理输入到您需要的特定目标范围地址中的数据/公式连接 VB.NET Excel COM 插件内部的选择更改事件。有多种方法可以做到这一点,但由于您使用 VB.NET,所以最好使用最新的方法,即构建 VSTO COM 插件。
关于如何最好地构建 VSTO 插件,还有许多其他问题(有些在 C# 中,有些在 VB.NET 中,但所有这些信息对于两者来说都是完全相同的,只是语法不同)。
所以你将需要两个项目。您现有的插件,加上 Excel VSTO 插件(您也可以在 VB.NET 中执行此操作)。

现在,在 SelectionChange 事件中,您应该确保您的代码正确处理目标范围; IE。确保您通过选择检查不连续的范围组... A1:B1;D2:E2 并将数据复制到您的应用程序。您可以考虑使用 xml 等格式来序列化 excel 中的最新数据,这样如果您的应用程序当时未打开,它可以在下次打开时反序列化并读回为其存储的数据。我想这实际上取决于您如何处理数据(即是否要加载到数据网格中?)以及您是否要进行进一步处理并稍后将其存储在其他地方(在这种情况下,也许您可​​以将其直接放入数据库中) excel 中的插件)。

The requirements:
you need to guarantee that when a user is using excel your app can collect the data. Your app may not be running at the time. You need the Worksheet_SelectionChange() event to fire automatically not just when your app is active.

Solution:
Basically in order to guarantee that the Worksheet_SelectionChange() is running all the time, and in order to guarantee that whenever the user opens an instance of excel you are able to collect and process the data/formulas entered into the particular target range address you need to wire up the selectionchange event inside of a VB.NET Excel COM Addin. There are several ways to do this, but since your using VB.NET your best off using the newest approach which is building a VSTO COM Addin.
There are numerous other questons available on how to best build a VSTO addin (some in C# some in VB.NET but all this information is exactly the same for both, just different syntax).
So you will need two projects. Your existing one, plus a Excel VSTO addin (which you can also do in VB.NET).

Now inside the selectionchange event you should make sure that your code handles the target range correctly; ie. make sure you check for non-contigious groups of ranges with a selection... A1:B1;D2:E2 and copy the data to your app. You may consider using a format such as xml to serialise the latest data from excel so that if your app is not open at the time, it can deserialise and read back the data stored for it the next time it is opened. I guess it really depends how your handling the data (i.e. is it for loading into a datagrid?) and whether you are going to do further processing and store it somewhere else later (in which case maybe you can put it straight into a database from the addin in excel).

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