gpt4 book ai didi

.net - Excel vsto 结束编辑模式

转载 作者:行者123 更新时间:2023-12-02 22:00:11 25 4
gpt4 key购买 nike

在 Excel COM 插件中,我需要访问 pageSetup 属性。但如果 Excel 中的编辑模式处于事件状态,我会遇到异常。

我可以使用以下代码检查编辑模式是否处于事件状态:

CommandBarControl oNewMenu = excelApp.CommandBars["Worksheet Menu Bar"].FindControl(
1, //the type of item to look for
18, //the item to look for
refmissing, //the tag property (in this case missing)
refmissing, //the visible property (in this case missing)
true); //we want to look for it recursively so the last argument should be true.

if ( oNewMenu != null )
{
// edit mode = true
if (!oNewMenu.Enabled) {
}
}

我找到了一些退出编辑模式的解决方案,但它们不起作用:

SendKeys.Flush();
excelApplication.SendKeys("{ENTER}");

如何退出编辑模式以便可以写入 pageSetup 属性?

最佳答案

如果您使用的是外接程序,您可以尝试使用此退出编辑模式:

Globals.ThisAddIn.Application.SendKeys("{ENTER}");

我会推荐与此类似的方法来确定 Excel 是否处于编辑模式:

public static void VerifyExcelIsNotInCellEditMode()
{
if (Globals.ThisWorkbook.Application.Interactive)
{
try
{
//Will throw an error if user is editing cell
Globals.ThisWorkbook.Application.Interactive = false;
Globals.ThisWorkbook.Application.Interactive = true;
}
catch
{
throw new Exception("Excel is in Edit Mode.");
}
}
}

关于.net - Excel vsto 结束编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22148825/

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