简体   繁体   English

用c#打开Excel; 有时没有菜单或窗口边框

[英]Opening Excel with c#; sometime without menus or Window border

From time to time I get reports from clients, and even from our QA, that opening excel from within our WinForms app causes Excel to open without its menus and window border. 我不时从客户甚至从质量保证部门那里获得报告,从WinForms应用程序中打开excel会导致Excel打开而没有菜单和窗口边框。 Only the formulabar and the sheet is seen floating around. 仅看到编辑栏和工作表在浮动。 This is reported to be very sporadic and I have never been ale to reproduce it myself in a develop environment and are clueless on what might be causing this. 据报道这是非常零星的,我从来没有在自己的开发环境中随意复制过它,也不知道是什么原因造成的。

Its been reported both with Excel 2003 and 2007. Excel 2003和2007均已报告了此问题。

Code: 码:

 Microsoft.Office.Interop.Excel.Application excel = new ApplicationClass
                       {
                           Visible = true,
                           WindowState = XlWindowState.xlNormal,
                           UserControl = true,
                           DisplayFullScreen = false,
                       };


 Workbook wb = excel.Workbooks.Open("c:/excel_test.xls",
                                              0, 
                                              false, 
                                              5, 
                                              "", 
                                              "", 
                                              false,
                                              XlPlatform.xlWindows, 
                                              "",
                                              true, 
                                              false, 
                                              0, 
                                              true, 
                                              false, 
                                              false);

Anyone that has an idea on whats wrong with this code or am I missing something. 任何对这段代码有什么问题有想法的人,或者我错过了什么。

Have you tried looking at the different properties that can be set on the application class? 您是否尝试过查看可以在应用程序类上设置的不同属性? Some of them might be of use to you. 其中一些可能对您有用。 Always try to be on the safe side, ie prefer setting a lot of parameters (even the ones you think need not be set), such as fullscreen = false etc, just to eliminate possible errors. 始终要保持安全性,即最好设置许多参数(甚至您认为不需要设置的参数),例如全屏= false等,只是为了消除可能的错误。

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.applicationclass_properties(v=office.11).aspx http://msdn.microsoft.com/zh-cn/library/microsoft.office.interop.excel.applicationclass_properties(v=office.11​​).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM