当前位置: 首页 > news >正文

借助Aapose.Cells 使用 C# 在 Excel 中读取、添加和编辑线程注释

Excel 中的线程注释是协作工作的重要功能。它允许多个用户在共享文档中添加、编辑和查看对话线程。在某些情况下,我们可能需要以编程方式管理这些线程注释。在这篇博文中,我们将学习如何使用 C# 在 Excel 中读取、添加和编辑线程注释。

Aspose.Cells 是Excel电子表格编程API,可加快电子表格的管理和处理任务,支持构建能够生成,修改,转换,呈现和打印电子表格的跨平台应用程序。同时不依赖于Microsoft Excel或任何Microsoft Office Interop组件,Aspose API 支持旗下产品覆盖文档、图表、PDF、条码、OCR、CAD、HTML、电子邮件等各个文档管理领域,为全球.NET 、Java、C ++等10余种平台开发人员提供丰富的开发选择。

用于管理线程评论的 C# Excel API

为了处理 Excel 工作表中的线程注释,我们将使用Aspose.Cells for .NET API。它是一个功能强大的电子表格编程 API,使开发人员能够在 .NET 应用程序中创建、操作和转换 Excel 文件。通过利用 Aspose.Cells for .NET,我们可以轻松地在 Excel 工作表中添加、读取、编辑或删除线程注释。

要使用 API,请下载 DLL或使用以下命令从NuGet安装它:

PM> Install-Package Aspose.Cells
使用 C# 在 Excel 中添加线程注释
  1. 创建Workbook类的实例。
  2. 通过索引访问特定工作表。
  3. 使用Add()方法将作者添加到ThreadedCommentAuthors集合。
  4. 通过索引获取新创建的作者的ThreadedCommentAuthor类对象。
  5. 使用AddThreadedComment()方法添加线程注释。该方法以单元格名称、注释文本和 ThreadedCommentAuthor 对象作为参数。
  6. 使用Workbook.Save(string)方法保存 Excel 文件。

以下代码示例显示如何使用 C# 向 Excel 工作表添加线程注释

// This code example demonstrates how to add threaded comments in an Excel worksheet
// Create an instance of the Workbook class
Workbook workbook = new Workbook();// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];// Add an Author
var authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add("Aspose Test", "", "");
var author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex];// Add Threaded Comment
worksheet.Comments.AddThreadedComment("A1", "Test Threaded Comment", author);// Save the output file
workbook.Save("AddThreadedComments_out.xlsx");
阅读 Excel 中特定单元格的线程注释

要从 Excel 工作表中的指定单元格读取线程注释,请按照以下步骤操作:

  1. 使用Workbook类加载现有的 Excel 文件。
  2. 通过索引访问工作表。
  3. 使用GetThreadedComments()方法获取特定单元格的线程注释。该方法以单元格名称作为参数。
  4. 循环浏览所有主题评论并阅读详细信息。

以下代码示例显示如何使用 C# 从 Excel 工作表中读取指定列的线程注释

// This code example demonstrates how to read threaded comments for a specified cell in an Excel worksheet
// Load an existing Excel file
Workbook workbook = new Workbook("AddThreadedComments_out.xlsx");// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];// Get Threaded Comments for a specific cell
var threadedComments = worksheet.Comments.GetThreadedComments("A1");// Read the threaded comments
foreach (var comment in threadedComments)
{
Console.WriteLine("Author Name: " + comment.Author.Name);
Console.WriteLine("Threaded comment Notes:" + comment.Notes);
}Author Name: author@domain.com
Threaded comment Notes:Test Threaded Comment
使用 C# 读取 Excel 中的所有主题注释

类似地,我们可以按照以下步骤读取 Excel 工作表中所有可用的主题评论:

  1. 使用Workbook类加载现有的 Excel 文件。
  2. 循环浏览所有评论并逐一阅读主题评论。

以下代码示例显示如何使用 C# 从 Excel 工作表读取所有线程注释

// This code example demonstrates how to read threaded comments for a specified cell in an Excel worksheet
// Load an existing Excel file
Workbook workbook = new Workbook("AddThreadedComments_out.xlsx");// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];// Get all the comments
var comments = worksheet.Comments;// Read all the threaded comments
foreach (var comment in comments)
{
// Process threaded comments
foreach (var threadedComment in comment.ThreadedComments)
{
Console.WriteLine("Author Name: " + threadedComment.Author.Name);
Console.WriteLine("Threaded comment author User Id: " + threadedComment.Author.UserId);
Console.WriteLine("Threaded comment author ProviderId:" + threadedComment.Author.ProviderId);
Console.WriteLine("Threaded comment Notes:" + threadedComment.Notes);
}
}
使用 C# 在 Excel 中编辑线程注释

请按照以下步骤更新 Excel 中的任何主题评论:

  1. 使用Workbook类加载现有的 Excel 文件。
  2. 通过索引访问工作表。
  3. 使用GetThreadedComments()方法获取特定单元格的线程注释。该方法以单元格名称作为参数。
  4. 更新评论的注释属性。
  5. 使用Workbook.Save(string)方法保存 Excel 文件。

以下代码示例展示如何使用 C# 编辑 Excel 工作表中的线程注释

// This code example demonstrates how to edit threaded comments in an Excel worksheet
// Load an existing Excel file
Workbook workbook = new Workbook("AddThreadedComments_out.xlsx");// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];// Get Threaded Comments for a specific cell
var threadedComments = worksheet.Comments.GetThreadedComments("A1");
var comment = threadedComments[0];// Update the comment note
comment.Notes = "Updated Comment";// Save the output file
workbook.Save("EditThreadedComments.xlsx");
使用 C# 删除 Excel 中的主题评论

我们还可以按照以下步骤删除Excel工作表中特定单元格的线程注释:

  1. 使用Workbook类加载现有的 Excel 文件。
  2. 通过索引访问工作表。
  3. 使用RemoveAt()方法从评论集合中删除评论。该方法以单元格名称作为参数。
  4. 使用Save(string)方法保存Excel文件。

以下代码示例显示如何使用 C# 删除 Excel 工作表中的线程注释

// This code example demonstrates how to delete threaded comments in an Excel worksheet
// Load an existing Excel file
Workbook workbook = new Workbook("AddThreadedComments_out.xlsx");// Get all the comments
var comments = workbook.Worksheets[0].Comments;// Remove Comments
comments.RemoveAt("A1");// Save the output file
workbook.Save("DeleteThreadedComments.xlsx");
结论

在本文中,我们学习了如何使用 C# 读取、添加、编辑和删除 Excel 工作表中的线程注释。通过利用 Aspose.Cell for .NET,您可以轻松地在 C# 应用程序中操作 Excel 工作表。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 从零开始学数据结构系列之第四章《什么是关键路径》
  • windows hook之进程防杀(任务管理器)
  • Python爬虫技术与K-means算法的计算机类招聘信息获取与数据分析
  • 小米便签——ui包详细解读
  • 基于Springboot网上蛋糕售卖店管理系统的设计与实现--论文pf
  • 配置oss cdn加速静态资源访问 阿里云
  • 【多线程开发 6】spring中的注解/API的线程问题
  • 基于Python的火车票售票系统/基于django的火车购票系统
  • 产品经理基础知识
  • C++ IO流
  • java中常用的设计模式
  • 苍穹外卖day10
  • uniapp快速回顾,新学websocket连接和BLE连接
  • TinyEngine是什么?
  • 大疆秋招笔试
  • Angular 响应式表单 基础例子
  • CSS魔法堂:Absolute Positioning就这个样
  • django开发-定时任务的使用
  • Docker下部署自己的LNMP工作环境
  • egg(89)--egg之redis的发布和订阅
  • JavaScript创建对象的四种方式
  • JavaScript设计模式之工厂模式
  • Laravel 菜鸟晋级之路
  • linux学习笔记
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • Nodejs和JavaWeb协助开发
  • React的组件模式
  • Vue 重置组件到初始状态
  • vue总结
  • 程序员最讨厌的9句话,你可有补充?
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 浅谈Golang中select的用法
  • 设计模式走一遍---观察者模式
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 通过来模仿稀土掘金个人页面的布局来学习使用CoordinatorLayout
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • #if 1...#endif
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (Matalb回归预测)PSO-BP粒子群算法优化BP神经网络的多维回归预测
  • (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
  • (独孤九剑)--文件系统
  • (翻译)Quartz官方教程——第一课:Quartz入门
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (附源码)springboot助农电商系统 毕业设计 081919
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (回溯) LeetCode 46. 全排列
  • (三十)Flask之wtforms库【剖析源码上篇】
  • (顺序)容器的好伴侣 --- 容器适配器
  • (转)mysql使用Navicat 导出和导入数据库
  • .env.development、.env.production、.env.staging
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .Net 6.0 处理跨域的方式
  • .NET 8 编写 LiteDB vs SQLite 数据库 CRUD 接口性能测试(准备篇)