用户可以向电子表格单元格添加注释并回复现有注释。讨论可以在单元的上下文中进行,而无需切换到其他通信工具(电子邮件、即时消息或项目管理软件)。
电子表格文档 API 允许您管理代码中的层级注释。您可以添加、编辑和删除评论。处理带有层级注释的文档时不会丢失内容。
注意:
电子表格文档 API 不会打印层级注释或将层级注释导出为 PDF 格式。
使用 Worksheet.ThreadedComments 属性可检索包含工作表中所有层级注释的 ThreadedCommentCollection。ThreadedCommentCollection.GetThreadedComments(CellRange) 方法允许您获取应用于指定单元格区域的所有注释。
下面的代码示例获取添加到 A1:G20 单元格区域的所有注释:
Vb.Net |
Dim workbook As New DevExpress.Spreadsheet.Workbook() workbook.LoadDocument("C:\Docs\Comments.xlsx") Dim worksheet As DevExpress.Spreadsheet.Worksheet = workbook.Worksheets(0) Dim comments As IList(Of DevExpress.Spreadsheet.ThreadedComment) = worksheet.ThreadedComments.GetThreadedComments(worksheet("A1:G20")) |
C# |
DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(@"C:\Docs\Comments.xlsx"); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[0]; IList<DevExpress.Spreadsheet.ThreadedComment> comments = worksheet.ThreadedComments.GetThreadedComments(worksheet["A1:G20"]); |
调用 ThreadedCommentCollection.Add 方法以向特定单元格添加线程注释。如果将单元格区域作为方法参数传递,则注释将添加到此区域的左上角单元格中。
可以传递字符串或 ThreadedCommentAuthor 实例来指定注释作者。该对象允许您指定将作者链接到其标识提供者(Windows Live ID、Office 365 等)的登录凭据。ThreadedCommentAuthor
下面的代码示例向 G16 单元格添加了注释:
Vb.Net |
Dim workbook As New DevExpress.Spreadsheet.Workbook() workbook.LoadDocument("C:\Docs\Comments.xlsx") Dim worksheet As DevExpress.Spreadsheet.Worksheet = workbook.Worksheets(0) Dim comments As DevExpress.Spreadsheet.ThreadedCommentCollection = worksheet.ThreadedComments Dim threadedComment As DevExpress.Spreadsheet.ThreadedComment = comments.Add(worksheet("G16"), "Sales Department", "The discount was approved by the Sales Director at the meeting on November 5th.") threadedComment.Resolved = True workbook.SaveDocument("C:\Docs\Comments_upd.xlsx") |
C# |
DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(@"C:\Docs\Comments.xlsx"); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[0]; DevExpress.Spreadsheet.ThreadedCommentCollection comments = worksheet.ThreadedComments; DevExpress.Spreadsheet.ThreadedComment threadedComment = comments[0]; comments.Add(worksheet["G16"], "Sales Department","The discount was approved by the Sales Director at the meeting on November 5th."); threadedComment.Resolved = true; workbook.SaveDocument(@"C:\Docs\Comments_upd.xlsx"); |
使用 ThreadedComment 类属性可更改注释参数。您可以更改注释的文本,并指定此注释是否解析线程。
下面的代码示例解析了该线程:
Vb.Net |
Dim workbook As New DevExpress.Spreadsheet.Workbook() workbook.LoadDocument("C:\Docs\Comments.xlsx") Dim worksheet As DevExpress.Spreadsheet.Worksheet = workbook.Worksheets(0) Dim comments As DevExpress.Spreadsheet.ThreadedCommentCollection = worksheet.ThreadedComments Dim threadedComment As DevExpress.Spreadsheet.ThreadedComment = comments.Add(worksheet("G16"), "Sales Department", "The discount was approved by the Sales Director at the meeting on November 5th.") threadedComment.Text = "This thread is resolved" threadedComment.Resolved = True |
C# |
DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(@"C:\Docs\Comments.xlsx"); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[0]; DevExpress.Spreadsheet.ThreadedCommentCollection comments = worksheet.ThreadedComments; DevExpress.Spreadsheet.ThreadedComment threadedComment =comments[0]; threadedComment.Text = "This thread is resolved"; threadedComment.Resolved = true; |
使用 ThreadedComment.Reply 方法添加回复。可以传递字符串或 ThreadedCommentAuthor 实例来指定注释的作者。
下面的代码示例添加了对第一条评论的回复:
Vb.Net |
Dim workbook As New DevExpress.Spreadsheet.Workbook() workbook.LoadDocument("C:\Docs\Comments.xlsx") Dim worksheet As DevExpress.Spreadsheet.Worksheet = workbook.Worksheets(0) Dim comments As DevExpress.Spreadsheet.ThreadedCommentCollection = worksheet.ThreadedComments Dim threadedComment As DevExpress.Spreadsheet.ThreadedComment = comments.Add(worksheet("G16"), "Sales Department", "The discount was approved by the Sales Director at the meeting on November 5th.") threadedComment.Reply("Nancy Davolio", "Thanks for the hint") workbook.SaveDocument("C:\Docs\Comments_upd.xlsx") |
C# |
DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(@"C:\Docs\Comments.xlsx"); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[0]; DevExpress.Spreadsheet.ThreadedCommentCollection comments = worksheet.ThreadedComments; DevExpress.Spreadsheet.ThreadedComment threadedComment =comments[0]; threadedComment.Reply("Nancy Davolio", "Thanks for the hint"); workbook.SaveDocument(@"C:\Docs\Comments_upd.xlsx"); |
以下方法允许您删除注释:
ThreadedCommentCollection.Remove:删除指定的注释或应用于单元格区域的注释。
ThreadedCommentCollection.RemoveAt:删除集合中指定索引处的注释。
下面的代码示例删除了指定作者的所有注释:
Vb.Net
Dim workbook As New DevExpress.Spreadsheet.Workbook()
workbook.LoadDocument("C:\Docs\Comments.xlsx")
Dim worksheet As DevExpress.Spreadsheet.Worksheet = workbook.Worksheets(0)
Dim comments = worksheet.ThreadedComments.Where(Function(comment) comment.Author.Name = "Nancy Davolio")
If comments IsNot Nothing Then
For Each comment As DevExpress.Spreadsheet.ThreadedComment In comments
worksheet.ThreadedComments.Remove(comment)
Next
End If
C# |
DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(@"C:\Docs\Comments.xlsx"); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[0]; var comments = worksheet.ThreadedComments.Where(comment => comment.Author.Name == "Nancy Davolio"); if (comments!=null) { foreach (var comment in comments) { worksheet.ThreadedComments.Remove(comment); } } |
Worksheet.Comments属性允许您管理简单的注释-Excel文档中的旧注释。有关详细信息,请参阅以下文章:如何:向单元格添加简单注释。
注释
Worksheet.Comments属性仅检索简单注释。返回值CommentCollection不包含线程注释。