【发布时间】:2017-11-07 07:31:07
【问题描述】:
我正在 C# 中创建 Windows 应用程序,其中自动化 MsOffice Excel。
我正在尝试让 excel 应用程序功能区当前处于隐藏/显示状态。
以下代码:
public static bool EvaluateRibbonDisplay(IQuestion question, string filename, ShowHide display)
{
ExcelInterop.Application excelApplication = null;
try
{
excelApplication = new ExcelInterop.Application() { Visible = false, DisplayAlerts = false, ScreenUpdating = false };
ExcelInterop.Workbook excelWorkbook = excelApplication.Workbooks.Open(filename);
bool result = false;
var abc = excelApplication.ExecuteExcel4Macro("Get.ToolBar(7,\"Ribbon\")"); \\always returing true
var abcd = excelApplication.CommandBars["Get.ToolBar(7,\"Ribbon\")"].Enabled;\\always returing true
if (excelApplication.ExecuteExcel4Macro("Get.ToolBar(7,\"Ribbon\")") == Convert.ToBoolean(EnumStringExtension.GetDescription(display)))
result = true;
excelWorkbook.Close();
return result;
}
catch (Exception)
{
return false;
}
finally
{
QuitApplication(excelApplication);
}
}
要隐藏/显示功能区,我使用 Ctrl+F1。但是上面的代码总是返回 true。
谁能帮帮我,我怎样才能获得功能区状态。
提前致谢。
【问题讨论】:
标签: excel windows c#-4.0 office-interop