在有些时候,我们可能需要在Excel文档中显示或隐藏注释,本文介绍如何使用Spire.XLS隐藏或显示Excel文档中的现有注释。
详细步骤:
Step 1:实例化一个Workbook实例并加载excel文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");
Step 2:获取第一个工作表
Worksheet sheet = workbook.Worksheets[0];
Step 3:隐藏或显示工作表中的具体注释
//Hide comment
sheet.Comments[0].IsVisible = false;
//Show comment
//sheet.Comments[0].IsVisible = true;
Step 4:保存文档
workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);
截图:
完整代码:
//Instantiate a Workbook instance and load the excel document
Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Hide the specific comment in the worksheet
sheet.Comments[0].IsVisible = false;
//Show the specific comment in the worksheet
//sheet.Comments[0].IsVisible = true;
//Save the document
workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);