VSTO ColumnChanging 事件未触发且 HasChanges 在 Excel 工作表上无法正常工作
一些背景:有一个用 c#、.net 4.0 编写的 Excel 的 VSTO 插件 Excel 有许多选项卡,其中使用数据集填充来自数据库的数据。当用户向工作表添加数据时,某些列会自动设置为默认数据。我们使用 DataSet 的 HasChanges 方法来检查数据是否有修改并突出显示它们。
一般来说,它运作得很好。但我们的一个用户站遇到了一个奇怪的问题。 ColumnChanging 事件不会被触发。此外,即使添加了新数据,DataSet.HasChanges 方法也会返回 false。
该问题仅发生在安装了 Excel 2007 的 Windows 7 计算机上。
我们尝试通过禁用宏在 DEV 计算机(Windows XP、Excel 2007)上重现该问题,但没有成功。显然我们无法在用户计算机上安装 Visual Studio。
您对如何重现和修复它有任何想法吗?也许是配置问题?
Some background: there is an VSTO plugin to Excel written in c#, .net 4.0
Excel has many tabs that are filled with data from database using DataSets. When users add data to sheet some columns are automatically set with default data. We're using HasChanges methods of DataSet to check if there were modifications in data and highlight them.
Generally it works pretty well. But we have a strange issue on one of users station. The ColumnChanging event is not fired. Additionally DataSet.HasChanges method is returning false even if the new data is added.
The problem only occurs on Windows 7 machine with Excel 2007 installed.
We tried to reproduce the problem on DEV machines (Windows XP, Excel 2007) by disabling macros but without success. We can't install Visual Studio on user machine obviously.
Do you have any ideas how to reproduce and fix it? Maybe it is configuration issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
客户端建议:
客户端上可能的安全设置。
有安装程序吗?如果是这样,请尝试卸载然后重新安装。
此外,从 SDK 获取调试器。您也许能够在客户端计算机上使用,具体取决于您的构建设置、配置设置以及是否部署了 pdb。
您是否修复了客户端上的.NET 4.0?
您是否修复了客户端上的 VSTO 4 Run-time?另外,VSTO 4 Run-time 也需要更新。
代码建议:
事件未触发的最可能原因是对象发生更改并且对事件的引用丢失。确保数据集永远不会更改。
确保事件处理程序尚未被删除。
可能存在错误导致数据集变量重置和事件丢失。
可能会处置然后创建另一个实例。
Client suggestions:
Possible security settings on client.
Is there an installer? If so, try uninstalling then re-installing.
Also, get the debugger from the SDK. You may be able to use on client machine depending on your build settings, configuration settings, and if you deployed the pdb.
Have you repaired .NET 4.0 on client?
Have you repaired VSTO 4 Run-time on client? Also there is a required update to VSTO 4 Run-time.
Code suggestions:
The most likely cause for an event not firing, is the object changes and the reference to the event is lost. Make sure the data set never changes.
Make sure there the event handlers have not been removed.
Possible there is an error causing the data-set variable to be reset and event lost.
Possible disposing then creating another instance.
它可以更可靠的UPD,您需要保留对原始对象的引用以使其保持活动状态(事件订阅是不够的)
尝试使用Application.SheetChange,当您处理包装的COM对象并订阅它的事件时,
Try using Application.SheetChange, it can be more reliable
UPD when you deal with wrapped COM object and subscribe to an event of it, you need to keep a reference to original object to keep it alive (event subscription is not enough)