分线评论

线程化的批注

MS Excel 365提供了一个添加分线评论的功能。这些评论可以用作对话,并可用于讨论。现在的评论带有一个回复框,允许进行分线对话。Excel 365中的旧注释称为注释。下面的截图显示了在Excel中打开分线评论时的显示方式。

todo:image_alt_text

在较旧版本的Excel中,分线评论显示如下。以下图片是打开在Excel 2016中的样本文件时拍摄的。

todo:image_alt_text

todo:image_alt_text

Aspose.Cells还提供了管理分线评论的功能。

添加分线评论

使用Excel添加分线评论

在Excel 365中添加分线评论,请按照以下步骤进行。

  • 方法1
    • 单击审阅选项卡
    • 单击新建评论按钮
    • 这将打开一个对话框,以输入活动单元格中的评论。
    • todo:image_alt_text
  • 方法2
    • 右键单击要插入评论的单元格。
    • 单击新建评论选项。
    • 这将打开一个对话框,以输入活动单元格中的评论。
    • todo:image_alt_text

使用Aspose.Cells添加分线评论

Aspose.Cells提供Comments.AddThreadedComment方法来添加分线评论。Comments.AddThreadedComment方法接受以下三个参数。

  • 单元格名称:要插入评论的单元格的名称。
  • 评论文本:评论的文本。
  • ThreadedCommentAuthor:评论的作者

以下代码示例演示了使用Comments.AddThreadedComment方法向单元格A1添加分线评论。请参考代码生成的输出Excel文件

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook();
// Add Author
int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add("Aspose Test", "", "");
ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex];
// Add Threaded Comment
workbook.Worksheets[0].Comments.AddThreadedComment("A1", "Test Threaded Comment", author);
workbook.Save(outDir + "AddThreadedComments_out.xlsx");

读取分线评论

使用Excel读取分线评论

要在Excel中读取分线评论,只需将鼠标悬停在包含评论的单元格上以查看评论。评论视图将类似于以下图像中的视图。

todo:image_alt_text

使用Aspose.Cells读取分线评论

Aspose.Cells提供Comments.GetThreadedComments方法来检索指定列的分线评论。Comments.GetThreadedComments方法接受列名称作为参数,并返回ThreadedCommentCollection。您可以遍历ThreadedCommentCollection以查看评论。

以下示例演示了通过加载 示例Excel文件 从A1列读取评论。请查看生成的代码控制台输出以供参考。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get Threaded Comments
ThreadedCommentCollection threadedComments = worksheet.Comments.GetThreadedComments("A1");
foreach (ThreadedComment comment in threadedComments)
{
Console.WriteLine("Comment: " + comment.Notes);
Console.WriteLine("Author: " + comment.Author.Name);
}

控制台输出

Comment: Test Threaded Comment

Author: Aspose Test

读取线程评论的创建时间

Aspose.Cells 提供 Comments.GetThreadedComments 方法来检索指定列的线程评论。 Comments.GetThreadedComments 方法接受列名称作为参数并返回 ThreadedCommentCollection。您可以遍历 ThreadedCommentCollection 并使用 ThreadedComment.CreatedTime 属性。

以下示例演示了通过加载 示例Excel文件 读取线程评论的创建时间。请查看生成的代码控制台输出以供参考。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get Threaded Comments
ThreadedCommentCollection threadedComments = worksheet.Comments.GetThreadedComments("A1");
foreach (ThreadedComment comment in threadedComments)
{
Console.WriteLine("Comment: " + comment.Notes);
Console.WriteLine("Author: " + comment.Author.Name);
Console.WriteLine("Created Time: " + comment.CreatedTime);
}

控制台输出

Comment: Test Threaded Comment

Author: Aspose Test

Created Time: 5/15/2019 12:46:23 PM

编辑线程评论

使用Excel编辑线程评论

要在Excel中编辑线程评论,请单击评论上显示的编辑链接,如下图所示。

todo:image_alt_text

使用Aspose.Cells编辑线程评论

Aspose.Cells 提供 Comments.GetThreadedComments 方法来检索指定列的线程评论。 Comments.GetThreadedComments 方法接受列名称作为参数并返回 ThreadedCommentCollection。您可以更新 ThreadedCommentCollection 中所需的评论并保存工作簿。

以下示例演示了通过加载 示例Excel文件 编辑A1列中的第一个线程评论。请查看生成的代码以供参考。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get Threaded Comment
ThreadedComment comment = worksheet.Comments.GetThreadedComments("A1")[0];
comment.Notes = "Updated Comment";
workbook.Save(outDir + "EditThreadedComments.xlsx");

删除线程评论

使用Excel删除线程评论

要在Excel中删除线程评论,请右键单击包含评论的单元格,然后单击下图所示的删除评论选项。

todo:image_alt_text

使用Aspose.Cells删除线程评论

Aspose.Cells 提供 Comments.RemoveAt 方法来删除指定列的评论。 Comments.RemoveAt 方法接受列名称作为参数并删除该列中的评论。

以下示例演示了通过加载sample Excel File文件来删除A1列中的注释。请参考代码生成的output Excel file

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
CommentCollection comments = worksheet.Comments;
// Get Author of first comment in A1
ThreadedCommentAuthor author = worksheet.Comments.GetThreadedComments("A1")[0].Author;
// Remove Comments
comments.RemoveAt("A1");
ThreadedCommentAuthorCollection authors = workbook.Worksheets.ThreadedCommentAuthors;
// Remove Author of first comment in A1
authors.RemoveAt(authors.IndexOf(author));
workbook.Save(outDir + "ThreadedCommentsSample_Out.xlsx");