简体   繁体   English

使用C#/ VSTO监视excel 2007内部的一系列单元格

[英]monitoring a range of cells inside of excel 2007 with C#/VSTO

I have a row in excel I'd like to translate into an ObserveableCollection in C# for binding/event purposes, so all accessor classes know they're getting the latest data from the source excel sheet. 我在excel中有一行,我想将其转换为C#中的ObservableCollection以便进行绑定/事件,因此所有访问器类都知道它们正在从源excel工作表获取最新数据。 How would this be done? 怎么做?

Clarification: I'm using an excel add-in project, not a workbook project, so am not sure whether or not XMLMappedRange Controls are an option. 澄清:我使用的是excel加载项项目,而不是工作簿项目,因此不确定是否可以选择XMLMappedRange控件。

Using VSTO you have a few options: 使用VSTO,您有几种选择:

  1. From the Excel.Worksheet class, you can access the Worksheet.Change event. Excel.Worksheet类,可以访问Worksheet.Change事件。
  2. From the NamedRange class, you can access the NamedRange.Change event (which uses the Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler delegate that you mentioned in another comment). NamedRange类,可以访问NamedRange.Change事件(该事件使用您在另一条注释中提到的Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler委托)。
  3. The NamedRange class also supports simple, one-way databinding via the DataBindings property, an example of which is shown in the discussion How do I bind an array to a NamedRange . NamedRange类还通过DataBindings属性支持简单的单向数据绑定 ,在如何将数组绑定到NamedRange的讨论中显示了一个示例。
  4. Another possibility is the XmlMappedRange control, which also supports databinding. 另一种可能性是XmlMappedRange控件,它也支持数据绑定。

A good primer on using the NamedRange and XmlMappedRange can be found here: The VSTO Programming Model . 可以在这里找到有关使用NamedRange和XmlMappedRange的良好入门知识: VSTO编程模型 A decent walkthrough using the NamedRange can be found in the Visual Studio Tools for Office (VSTO) 2005 Guided Tour . Visual Studio Tools for Office(VSTO)2005 Guided Tour中可以找到使用NamedRange的不错的演练。

I hope this helps... 我希望这有帮助...

Mike 麦克风

您可以在范围更改事件中添加OnChanged。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM