簡體   English   中英

用C#代碼隱藏Excel文檔中的工具欄

[英]C# code to Hide toolbars in an excel document

我有一個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);

我一直在調查您的案子,我認為使用Excel.Application可以找到答案。

顯然,您需要執行以下操作:

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

試試看,讓我知道,如果它不起作用,我們會解決的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM