显示Excel“开始屏幕”在背景中打开工作簿后(可见= false)
我创建了一个使用.xlsx作为配置文件的C#的VSTO Excel加载项。
配置文件是在ribbondropdown_itemssloading
中通过
private void RibbonDropDown_ItemsLoading(object sender, RibbonControlEventArgs e)
{
//Keep the config template always open
AddInFunctions.chkConfigTemplateState();
\\--> Excel.Application.Workbooks.Open(UserXLSConfigTemplateFilePath).Windows[1].Visible = false
//add list of names from tmpConfigNames
rbnDropDown.Items.Clear();
//add new items to drpDwnSelectNoteTemplate from AddInFunctions.tmpConfigNames()
foreach (string s in AddInFunctions.tmpConfigNames())
{
RibbonDropDownItem rdi = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
rdi.Label = s;
Globals.Ribbons.Ribbon1.rbnDropDown.Items.Add(rdi);
}
}
此过程打开的,但是通过单击Excel图标,用户可以通过Excels启动过程进行干预。 的最后一个支架之后
在
ribbondropdown_itemsloading
已选中:打开我的配置文件隐形可以防止出现“启动屏幕”
- >是否没有选中:Excel崩溃
最终我应该以不同的步骤加载文件?
最终的目标是尊重启动选项:
- 则仍应向用户呈现
- 如果通常打开启动屏幕,如果通常不打开启动屏幕,
- ,如果用户使用用户看到Excel开放 ,请向用户提供空白Excel新工作簿这也不应该改变 ;
测试:
- 通过//:成功加载Excel&amp addin
- 不要隐藏工作簿 - >设置可见= true:相同的崩溃行为
- 不要添加这些项目:相同的崩溃行为
- 从opentemplate函数中删除应用程序筛选函数:相同的崩溃行为
eventlog :
程序'[768] excel.exe'已使用代码3221225477(0xc0000005)退出。
EventData
1881252799848305173
4
APPCRASH
Not available
0
excel.exe
16.0.15225.20288
62a3df4b
mso98win32client.dll
0.0.0.0
62a31f70
c0000005
000000000001a267
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER9130.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_excel.exe_ee94e2c752da07819d933041028d3f5d2787_fd09608a_4640236e-8eec-4fed-8501-452bbbe40250
0
cf4dbc3b-9995-40b9-a9c6-7ad4cbf1ebce
268435456
a88fa5fe3d21b47d3a1b8d7443aad215
0
I have created a VSTO Excel Add-In with C# which uses a .xlsx as a configuration file.
The configuration file is opened within RibbonDropDown_ItemsLoading
by
private void RibbonDropDown_ItemsLoading(object sender, RibbonControlEventArgs e)
{
//Keep the config template always open
AddInFunctions.chkConfigTemplateState();
\\--> Excel.Application.Workbooks.Open(UserXLSConfigTemplateFilePath).Windows[1].Visible = false
//add list of names from tmpConfigNames
rbnDropDown.Items.Clear();
//add new items to drpDwnSelectNoteTemplate from AddInFunctions.tmpConfigNames()
foreach (string s in AddInFunctions.tmpConfigNames())
{
RibbonDropDownItem rdi = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
rdi.Label = s;
Globals.Ribbons.Ribbon1.rbnDropDown.Items.Add(rdi);
}
}
This process however intervense with Excels startup procedure given that the user opens Excel by clicking on the Excel icon. Right after the last brace of RibbonDropDown_ItemsLoading
When Option toggle "Show the Start screen when this application starts":
--> is checked: opening my config file invisible prevents the "Start screen" to come up
--> is unchecked: Excel crashes
eventually I should load the file at a differnt step?
Ultimatly the goal is to respect the start up options:
- If start screen is usually opened it should still be presented to the user
- If start screen is usually not opened, present the user with a blank Excel
- If user is used to seeing excel opening with a new workbook this shouldn't change too
etc.
Tests:
- inactivate both steps by //: successfully loading Excel & AddIn
- don't hide workbook --> set visible = true: same crash behaviour
- don't add the items just load template: same crash behaviour
- remove application screenupdate from openTemplate Function: same crash behaviour
EventLog:
The program '[768] excel.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.
EventData
1881252799848305173
4
APPCRASH
Not available
0
excel.exe
16.0.15225.20288
62a3df4b
mso98win32client.dll
0.0.0.0
62a31f70
c0000005
000000000001a267
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER9130.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_excel.exe_ee94e2c752da07819d933041028d3f5d2787_fd09608a_4640236e-8eec-4fed-8501-452bbbe40250
0
cf4dbc3b-9995-40b9-a9c6-7ad4cbf1ebce
268435456
a88fa5fe3d21b47d3a1b8d7443aad215
0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是由于列表事件触发器的设置而发生的,这是在功能区加载时设置的。
当双击设计器视图中的功能区组件时,VS将为该组件添加一个事件,向开发人员提供类似的代码行:
我没有看到的是添加到的代码行ribbon.designer.cs:
现在,当Addin仍在加载事件时,该事件将被触发,这是没有意义的,并且在禁用了开始屏幕选项时会引起开始启动屏幕,并导致Excel崩溃。
请注意,我不完全理解导致行为的原因,而是从coribbon.designer.cs删除该代码线已解决了我的问题中描述的问题。
The problem occured because of the DropDown event trigger was set of while the ribbon was loading.
When one double clicks a ribbon component in the Designer View, VS will add an event for that component presenting the developer with a prepared line of code like this one:
what I didn't see however is the line of code that is being added to the ribbon.designer.cs:
Now while the AddIn is still loading the event will get triggered which makes no sense really and provokes surpressing the start screen and causes excel to crash if the start screen option is disabled.
Note that I do not fully understand what causes the behaviour but removing that line of code from Ribbon.Designer.cs has solved the issues described in my Question.
功能区加载中打开的,不适合此类内容。在此时间点,不得初始化办公申请以进行任何操作。我建议使用
startup
thisAddin
类实现的回调。The ribbon callbacks are not appropriate place for such things. The Office applications may not be initialized to make any operations at this point of time. I'd suggest using the
Startup
callback of yourThisAddin
class implementation.