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

相关文章
相关标签/搜索