我想从功能区控件中获取事件范围。只有当功能区上的控件需要时,才应该有一种方法可以访问选定的单元格。
目前我就是这样做的;
public partial class ThisAddin
{
private void SheetSelectionChange(object sh, Range target)
{
int count = target.Count;
if (count < 5000) // This is for performance reasons
{
//Set a custom range property in the office ribbon
Req_Tool.ActiveRange = target;
{
}
}
我觉得这是软弱和浪费。
首先,每次选择更改时,我的代码都会运行。
其次,无论是否使用过,我都有两份选集。
必须有更好的方法来做到这一点,我忽略了。
最佳答案
您可以通过访问 Application
对象的 Selection
属性来访问事件工作表中当前选定的范围。
private void button1_Click(object sender, RibbonControlEventArgs e)
{
this.ActiveRange = (Excel.Range)Globals.ThisAddIn.Application.Selection;
}
MSDN 文档:
关于c# - 如何从办公室功能区控件中获取选定的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11909091/