分线评论

线程化的批注

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-Java
// The path to the documents directory.
String dataDir = "";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Add Author
int authorIndex = workbook.getWorksheets().getThreadedCommentAuthors().add("Aspose Test", "", "");
ThreadedCommentAuthor author = workbook.getWorksheets().getThreadedCommentAuthors().get(authorIndex);
// Add Threaded Comment
workbook.getWorksheets().get(0).getComments().addThreadedComment("A1", "Test Threaded Comment", author);
workbook.save(dataDir + "AddThreadedComments_out.xlsx");

读取分线评论

使用Excel读取分线评论

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

todo:image_alt_text

使用Aspose.Cells读取分线评论

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

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

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = "";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get Threaded Comments
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("A1");
for (Object obj : threadedComments)
{
ThreadedComment comment = (ThreadedComment) obj;
System.out.println("Comment: " + comment.getNotes());
System.out.println("Author: " + comment.getAuthor().getName());
}

控制台输出

Comment: Test Threaded Comment

Author: Aspose Test

读取线程评论的创建时间

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

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

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = "";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get Threaded Comments
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("A1");
for (Object obj : threadedComments)
{
ThreadedComment comment = (ThreadedComment) obj;
System.out.println("Comment: " + comment.getNotes());
System.out.println("Author: " + comment.getAuthor().getName());
System.out.println("Created Time: " + comment.getCreatedTime());
}

控制台输出

Comment: Test Threaded Comment

Author: Aspose Test

Created Time: 2019-05-15T12:46:23

编辑线程评论

使用Excel编辑线程评论

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

todo:image_alt_text

使用Aspose.Cells编辑线程评论

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

以下示例演示了通过加载 sample Excel File 编辑A1列中的第一个线程化评论。请参考代码生成的 output Excel file,显示更新后的评论。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = "";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get Threaded Comment
ThreadedComment comment = worksheet.getComments().getThreadedComments("A1").get(0);
comment.setNotes("Updated Comment");
workbook.save(dataDir + "EditThreadedComments.xlsx");

删除线程评论

使用Excel删除线程评论

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

todo:image_alt_text

使用Aspose.Cells删除线程评论

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

下面的示例演示了如何通过加载 示例 Excel 文件 来删除 A1 列中的注释。请参考代码生成的 输出 Excel 文件

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = "";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx");
//Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
CommentCollection comments = worksheet.getComments();
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("I4");
ThreadedCommentAuthor author = threadedComments.get(0).getAuthor();
comments.removeAt("I4");
ThreadedCommentAuthorCollection authors = workbook.getWorksheets().getThreadedCommentAuthors();
authors.removeAt(authors.indexOf(author));
workbook.save(dataDir + "ThreadedCommentsSample_Out.xlsx");