在 Excel 文档中隐藏工具栏的 C# 代码

发布于 2024-10-03 07:51:50 字数 992 浏览 0 评论 0原文

我有一个 C# Winforms 程序,可以使用下面的代码打开一个 excel 文档。 它工作得很好,但我不知道该怎么做,就是关闭所有菜单和工具栏。

我现在使用的excel版本是2003...但我将在不久的将来升级到2010。 有什么想法吗?

//top of source...
using Excel = Microsoft.Office.Interop.Excel;

// Code inside a function...

// Get report and display it on the screen.
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();

xlWorkBook = xlApp.Workbooks.Open(strFileName, 0, true, 5, "", "", true,Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlApp.Visible = true;
xlApp.DisplayFullScreen = true;

 // Display the Document and then Sleep.
System.Threading.Thread.Sleep(timeToShowMilliseconds);

// Close the Excel report 
 xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();

releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);

I have a C# Winforms program that opens an excel document with the code below.
It works great but what I can not figure out how to do, is to turn off ALL menu's and toolbars.

The excel version I am using right now is 2003... But I will be upgrading to 2010 in the near future.
Any ideas?

//top of source...
using Excel = Microsoft.Office.Interop.Excel;

// Code inside a function...

// Get report and display it on the screen.
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();

xlWorkBook = xlApp.Workbooks.Open(strFileName, 0, true, 5, "", "", true,Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlApp.Visible = true;
xlApp.DisplayFullScreen = true;

 // Display the Document and then Sleep.
System.Threading.Thread.Sleep(timeToShowMilliseconds);

// Close the Excel report 
 xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();

releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);

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

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

发布评论

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

评论(1

再可℃爱ぅ一点好了 2024-10-10 07:51:50

我一直在调查您的案例,我认为 Excel.Application你可以找到答案。

显然你需要做的是这样的:

Excel.Application xlApp;
xlApp.CommandBars("tabName").Controls("File").Enabled = false;

尝试一下并告诉我,如果不起作用我们会想办法。

I've been looking into your case and i think with Excel.Application you can find the answer.

Apparently what you need to do is something like this:

Excel.Application xlApp;
xlApp.CommandBars("tabName").Controls("File").Enabled = false;

try it and let me know, if it doesnt work we'll figure something out.

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