我正在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。但上面的代码总是返回真实。
任何人都可以帮助我,我怎样才能获得功能区状态。
提前致谢。
答案 0 :(得分:0)
对我来说,功能区中第一个控件的高度会在隐藏时发生变化。可见= 145,隐藏= 57.希望你能用这种观察做点什么
@echo off
setlocal
@echo.
@echo Searching, please wait as this can take a while...
@echo.
for /F "usebackq delims=" %%i in (`cleartool ls -rec ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed" ^| find /V "-->" ^| find /V ".settings" ^| find /V "jar" ^| find /V "keep" ^| find /V "target" ^| find /V ".classpath" ^| find /V ".project" ^| find /V "%~n0" `) do ( if not exist %%i\* @echo "%%i")
@echo.
@echo === === === === === Search Complete === === === === === ===
@echo.
@echo.
pause