如何使用C#编程地使用VSTO组件关闭Excel Workbook

发布于 2025-02-05 15:20:43 字数 196 浏览 2 评论 0原文

在Excel中更新后,需要立即关闭工作簿。 如果我编写环境.exit(),则它立即关闭,但在再次打开同一Excel应用程序后不久。我尝试了Globals.thisworkbook.close(0);这关闭了相关的应用程序,表格,但我必须手动关闭Excel。更新后,请帮助我关闭工作簿。

我的应用程序是一个基于Windows的应用程序,带有VSTO组件(Excel)

After updating in excel, there is a requirement of closing the Workbook immediately.
If I write Environment.Exit(), then it closes immediately but soon after opening again the same excel application. I tried with Globals.ThisWorkBook.Close(0); this closes the application related, sheet but I manually have to close Excel. Please help me close the Workbook after update happens.

My Application is a windows based app with VSTO assemblies(excel)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-02-12 15:20:44

使用 application.quit.quit Microsoft Excel。这是MSDN所说的:

如果您使用此方法时未保存的工作簿是打开的,则Excel将显示一个对话框,询问您是否要保存更改。您可以通过在使用退出方法或将DisplayAlerts属性设置为False之前保存所有工作簿来防止这种情况。当此属性为False时,Excel使用未保存的工作簿退出时不会显示对话框;它退出而不保存它们。

如果您将保存的属性设置为工作簿的属性,而不将工作簿保存到磁盘上,则Excel将辞职而无需您保存工作簿。

For Each w In Application.Workbooks 
 w.Save 
Next w 
Application.Quit

Use the Application.Quit method which quits Microsoft Excel. Here is what MSDN states:

If unsaved workbooks are open when you use this method, Excel displays a dialog box asking whether you want to save the changes. You can prevent this by saving all workbooks before using the Quit method or by setting the DisplayAlerts property to False. When this property is False, Excel doesn't display the dialog box when you quit with unsaved workbooks; it quits without saving them.

If you set the Saved property for a workbook to True without saving the workbook to the disk, Excel will quit without asking you to save the workbook.

For Each w In Application.Workbooks 
 w.Save 
Next w 
Application.Quit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文