多次关闭提示保存
我用的是VS2008。在我的应用程序中,我从 MMC 管理单元运行 Excel 2003 工作表(在 Office 2007 中),以便用户可以修改某些参数。
该代码订阅了BeforeClosing 事件、Window Deactivate 和WindowActivate。只有当用户选择关闭Excel应用程序,提示他保存文件是/否/取消,并且工作表从不/总是保存后,一切才能顺利进行。问题是我正在使用 Workbook.Close() 来实际关闭该死的东西。它的第一个参数是一个布尔值,如果为 true 则每次都会保存,为 false 则从不保存,如果为 Type.missing 则关闭时会再次提示。因此,用户会被提示一次(这个只有取消功能),然后 Workbook.Close() 再次提示用户保存(这个有是/否功能,但没有取消功能 - 即使您单击它也会关闭取消)。
不,我尝试订阅 BeforeSave 事件,并尝试将其放入 beforeClose 中,但它没有触发;此外,强制保存也不是解决方案,跳过关闭工作簿并终止 excel(以避免工作簿关闭)也不是解决方案。
我还尝试通过简单地释放与工作簿关联的 com 对象来避免 workbook.close,但无济于事。
需要注意的一件事是,如果您单击“文件保存”,则会出现一个对话框,通知您如果保存电子表格,某些功能可能在 Office 2003 中不可用(该额外的对话框会成为问题吗?)
一种可能的解决方案(一种作为最后的手段,我会在关闭时抑制保存提示,并从代码中触发我自己的对话框(我可以控制的对话框)并读取结果并相应地执行操作(我想避免这种情况,因为它必须翻译成 20 多种语言,并且需要花费很多时间...)
我不知道解决方案,如果您有任何想法,我将非常感激。
I am using VS2008. In my application, from a MMC snap-in I run an Excel 2003 Worksheet (in Office 2007) so that the user can modify certain parameters.
The code is subscribed to the BeforeClosing Event, Window Deactivate and WindowActivate. Everything runs smoothly only after the user chooses to close the Excel app, he is prompted to save the file yes/no/cancel, and the sheet is never/always saved. Problem is that I am using Workbook.Close() to actually close the damn thing. It's first parameter is a bool if it's on true it will save everytime, on false never, and on Type.missing it will prompt again on close. So the user is prompted once (this one has only the cancel functionality) and then he is prompted again by the Workbook.Close() to save (this one has yes/no functionality but no cancel functionality - it will close even if you click cancel).
No I've tried to subscribe to the BeforeSave event and tried to put that in the beforeClose but it doesn't fire; Also force saving is not a solution and skip closing the workbook and kill excel (to avoid workbook close) is also not a solution.
I've also tried to avoid workbook.close by simply releasing the com object associated to the workbook, but to no avail.
One thing to note, if you click file-save, a dialog box appears informing you that if you save the spreadsheet some functionality may not be available in office 2003 (could that extra dialog box be a problem?)
One potential solution (one that I would have as a last resort) would be to supress the save prompt on close and fire my own dialog box from code (a dialog box that I can control) and read the result and do things accordingly (I want to avoid this because it has to be translated in 20+ languages and takes a lot of time...)
I am at a loss for solutions, if you have any ideas i would be very grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已解决:
我的一位同事终于破解了它...显然,直接关闭 Excel 时存在一些问题,因此使用委托线程休眠 1 秒然后终止 Excel 应用程序的基本方法,它能够保存(如果由用户请求)并成功退出。
SOLVED:
A colleague of mine finally cracked it... Apparently there were some issues when direcly closing Excel, so with a rudimentary approach of delegating a Thread to sleep 1 second and then killing the Excel app, it was able to save (if it was requested by the user) and successfully exit.
您还可以设置交互式属性 为假。这将阻止 XL 显示任何对话框。
You can also set Interactive property to false. This will prevent XL from showing any dialog.