Excel控件Spire.XLS 教程:在C#中保護工做表時隱藏公式

若是您的工做表有一些不但願別人查看的重要公式,則可能須要隱藏這些公式。 本文演示如何使用Spire.XLS和C#保護工做表時隱藏公式。html

XlsRange.IsFormulaHidden屬性用於肯定工做表受保護時是否隱藏公式。 您能夠經過將XlsRange.IsFormulaHidden屬性設置爲true來隱藏特定單元格區域中的公式,但請注意只有在工做表受保護時才能隱藏公式,若是在工做表處於工做表保護狀態時它們不會被隱藏。ide

//Initialize an object of Workbook class 
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Input.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];

//Hide the formulas in the used range
sheet.AllocatedRange.IsFormulaHidden = true;

//Protect the worksheet with password
sheet.Protect("123");

//Save the file
workbook.SaveToFile("HideFormulas.xlsx", ExcelVersion.Version2013);

截圖:orm

圖片1

慧都控件網htm

相關文章
相關標籤/搜索