gpt4 book ai didi

c# - VSTO获取Excel范围并放入文本框

转载 作者:行者123 更新时间:2023-11-30 21:56:39 24 4
gpt4 key购买 nike

我创建了一个自定义任务 Pane ,上面有一些输入。输入之一是文本框。

我想要做的是单击文本框,然后拖动选择一个单元格范围并将范围设置为文本框。

例如,条件格式对话框窗口具有此功能。

如果我从自定义任务 Pane 更改为 Excel,我应该使用什么事件?

enter image description here

最佳答案

在您的无模式表单中,只需将事件处理程序添加到 WorkSheet.SelectionChanged 事件。

像这样:

public partial class Form1 : Form
{
Microsoft.Office.Interop.Excel.Worksheet ws;

public Form1()
{
InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ws = Globals.ThisAddIn.Application.ActiveSheet;
ws.SelectionChange += ws_SelectionChange;

}

void ws_SelectionChange(Microsoft.Office.Interop.Excel.Range Target)
{
this.textBox1.Text = Target.Address;
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
ws.SelectionChange -= ws_SelectionChange;
}

}

希望对你有帮助

关于c# - VSTO获取Excel范围并放入文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31392544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com