C# 编辑、修改、删除Excel批注

 时间:2024-11-21 10:37:54

此条经验将介绍如何来编辑、修改、删除Excel中已有的批注内容。

工具/原料

Spire.XLS for .NET 8.0

Visual Studio

dll引用

1、下载安装该类库后,注意添加引用Spire.Xls.dll。dll文件可在安装路径下的Bin文件夹中获取。

C# 编辑、修改、删除Excel批注

1.编辑、修改Excel批注

1、【C#】using System;using Spire.Xls;using System.Drawing;namespace Modify潮贾篡绐Comment_XLS{ class Program { static void Main(string[] args) { //创建一个Workbook类对象,并加载Excel文档 Workbook workbook = new Workbook(); workbook.LoadFromFile("AddComment.xlsx"); //获取第一个工作表 Worksheet sheet = workbook.Worksheets[0]; //修改工作表中的第一个批注 ExcelComment comment0 = workbook.Worksheets[0].Comments[0]; sheet.Comments[0].Text = "This is a new comment"; //设置指定批注不可见(隐藏) sheet.Comments[0].IsVisible = true; //设置指定批注可见(显示) sheet.Comments[1].IsVisible = false; //保存并打开文档 workbook.SaveToFile("ModifyComment.xlsx", ExcelVersion.Version2013); System.Diagnostics.Process.Start("ModifyComment.xlsx"); } }}

2、调试运行程序,生成文档,下图是Excel批注编辑前后效果对比:

C# 编辑、修改、删除Excel批注C# 编辑、修改、删除Excel批注

2. 删除Excel批注

1、【C#】using Spire.Xls;namespace RemoveComments_XLS{ class Program { static void Main(string[] args) { //实例化Wordbook类实例并加载Excel文档 Workbook workbook = new Workbook(); workbook.LoadFromFile("Comments.xlsx"); //获取第一个工作表 Worksheet sheet = workbook.Worksheets[0]; //删除工作表中的第一个批注 sheet.Comments[1].Remove(); //保存并打开文档 workbook.SaveToFile("RemoveComment.xlsx", ExcelVersion.Version2013); System.Diagnostics.Process.Start("RemoveComment.xlsx"); } }}

2、调试运行程序之后,原有的Excel批注将不再有。

  • Windows下Python小时定时任务设置
  • 图形报表FineReport中如何进行单系列图表排序
  • vba 如何给word设置边距
  • 如何利用python的pygal模块绘制水平条形图
  • Excel VBA如何获取数组索引的范围
  • 热门搜索
    ct是什么意思 得意的近义词是什么 打量的近义词是什么 什么是安置房 阴历是什么 neither是什么意思 something是什么意思 珀莱雅适合什么年龄 两融余额是什么意思 scoop是什么意思