c# - Microsoft Excel 中用于注释的 OpenXML

标签 c# excel office365 openxml threaded-comments

我正在运行最新的 Office 365 Excel 版本 1901。我已经更新到最新的 OpenXml SDK,但我无法弄清楚如何以编程方式读取有关线程评论的信息,因为我看到的只是完整的摘要评论。甚至使用最新的 OpenXml Nuget 包。

如果我将 Excel 文档转换为 .zip 文件,我可以看到“threadedComments.xml”文件,其中包含我需要的内容,但不知道如何在 C# .NET 中以编程方式进行处理。

最佳答案

我知道,您没有关注 VBA,但新的 CommentThreaded 对象现在至少可以工作(Excel 版本 1906,2019 年 6 月测试)。
我实际上在 Visual Studio C# 中测试过它,但它似乎仍然不受支持。

截至 2019 年 5 月 15 日,新对象 CommentThreadedMicrosoft 描述.
在我的 Excel 版本 1906 中,它完全支持 VBA。

这里有一些 VBA 代码来解释一下处理:

Private Sub ExcelsNewCommentThreaded()
    Dim AllCommentsThreaded As Excel.CommentsThreaded
    Dim OneCommentThreaded As Excel.CommentThreaded
    Dim AllReplies As Excel.CommentsThreaded
    Dim OneReply As Excel.CommentThreaded
    Dim r As Range

    Set AllCommentsThreaded = ActiveSheet.CommentsThreaded

    ' loop over all threaded comments of a worksheet and get their info
    For Each OneCommentThreaded In AllCommentsThreaded
        With OneCommentThreaded
            Debug.Print .Author.Name, .Date, .Text
            For Each OneReply In .Replies
                With OneReply
                    Debug.Print .Author.Name, .Date, OneReply.Text
                End With
            Next OneReply
        End With
    Next OneCommentThreaded

    Set r = Selection.Cells(1)

    ' check if the selected cell already contains a threaded comment
    If r.CommentThreaded Is Nothing Then
        r.AddCommentThreaded ("my new comment")
    End If

    With r.CommentThreaded
        ' get text of comment
        Debug.Print .Text

        ' add some replies
        .AddReply ("my reply 1")
        .AddReply ("my reply 2")

        ' change text of comment
        Debug.Print .Text(Text:="text of comment changed")
        Debug.Print .Text

        ' change text of a reply
        .Replies(1).Text Text:="text of reply 1 changed"
        Debug.Print .Replies(1).Text

        ' delete second reply
        .Replies(2).Delete

        ' delete whole comment including its replies
        .Delete
    End With
End Sub

关于c# - Microsoft Excel 中用于注释的 OpenXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54569304/

相关文章:

powershell - 从列表中删除 ContentType Office 365

office365 - Office 365 API Ruby 示例应用程序已损坏

c# - 第三方 WPF 控件 : Devexpress vs Telerik

c# - 进程的可用内存

vba - 在 VBA 中命名和引用图表

excel - 如何从 Power Query 中的上一行获取列值?

office365 - 如何在 Office 365 中确定我的日历事件的创建者?

c# - 从 Unity 项目进行 REST 调用

c# .NET 绿屏背景移除

Excel - 平均值、最小值、最大值和 13 :00 for each day