1

我正在尝试确定以编程方式从 Microsoft Word 文档 (docx) 中提取“编辑器”的最佳方法 - 特别是当您通过“审阅”选项卡->“保护”部分,“限制编辑”选项->“2.编辑限制”部分->“个人”列表框。如果这可能在没有代码的情况下以某种方式实现,我提到 SharePoint 将用于在工作流期间提取此信息。

我相信我可以通过解压缩文件并在 document.xml 文件中搜索“w:permStart”节点来做到这一点,我不愿诉诸这种黑客攻击,因为如果微软决定它可能会在某个时候中断改变事情。

Office API 似乎提供了一种可能性(编辑器界面),但我现在无法测试它,我不肯定它甚至处于 api 的正确级别,因为它是一个接口而不是文档对象的实际属性或类似的。


编辑

Word 2010 UI 通过打开面板的按钮(或Word 2007 中的按钮)列出了我要在Review选项卡下、Protect功能区区域中提取的名称。Restrict EditingProtect DocumentRestrict Formatting and Editing

在此面板的第二部分(标记为2. Editing restrictions)中,如果没有标记为Individuals(Underneath Exceptions (optional))的框,请选中该Allow only this type of editing in the document复选框(在其后的下拉列表中选择什么并不重要)。

这将允许在该Exceptions (optional)部分下添加用户,这是通过单击More users...链接打开一个对话框来完成的,在该对话框中键入电子邮件地址(连接到 Microsoft 身份验证服务器)或域用户帐户(如果 Word 在域系统上运行时间)用分号隔开。这些用户将被添加到标有标签的列表中Individuals- 这是我想从 word 文档中提取的列表(如下图所示)。

此列表用于对下拉列表中指定的一般文档规则进行“例外”,并且只会保存与给定例外范围关联的名称 - 通过将电子邮件或名称添加到列表中来创建范围,选择一个块文本(或整个文档),然后选中该名称旁边的复选框以将其与所选范围相关联。保存文档时,对该名称的引用将作为w:ed一个或多个w:permStart元素的属性添加到基础 document.xml 文件(每个文本范围一个元素)

可以解压缩 docx 文件,解析 document.xml 文档并提取这些元素中这些属性中的所有名称,但如果有 Microsoft Word API 替代方法,那将非常不雅 - 我更喜欢通过 API因为它几乎肯定会更易于维护和稳定。

审查->保护->限制编辑->限制->个人

4

3 回答 3

1

好的,我知道 Word 将这些数据隐藏在哪里了 :)

我所做的是记录一个我在文档中添加编辑器的宏,并从那里对其进行逆向工程。

似乎编辑器被分配给范围。如果该部分不是太复杂,那么这应该可以帮助您完成大部分工作:

Dim wordApp As New Word.Application
Dim wordDocument As Word.Document = wordApp.Documents.Open("C:\MyDoc.docx")

Dim allEditors As Word.Editors = wordDocument.Range(0, 0).Editors
For i As Integer = 1 To allEditors.Count
    Debug.Print(allEditors.Item(i).Name)
Next

wordDocument.Close()
于 2013-02-22T03:19:19.700 回答
0

这将为您提供在当前文档中有修订的所有作者的列表。它并不漂亮,但它演示了一种提取它们的方法。

您没有指定 VB.Net 或 C#,但我认为如果这是您的首选语言,您可以将其转换为 C#。

Imports Microsoft.Office.Interop
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim wordApp As New Word.Application
        Dim wordDocument As Word.Document = wordApp.Documents.Open("c:\MyDoc.docx")
        Dim editors As New Dictionary(Of String, String)

        ' Iterate through all the revisions
        For Each r As Word.Revision In wordDocument.Revisions()
            If Not editors.ContainsKey(r.Author.ToString) Then
                editors.Add(r.Author.ToString(), r.Author)
            End If
        Next

        ' List all the unique authors
        For Each s As String In editors.Values
            Debug.Print(s)
        Next
        wordDocument.Close()
    End Sub
End Class

希望有帮助!

于 2013-02-19T21:28:09.590 回答
0

你可以试试这个:

    for (int j = 1; j <= wordDocument.Sections.Count; j++)

            {
                for (int i = 1; i <= wordDocument.Sections[j].Range.Editors.Count; i++)
                {
                      //your code here
                    wordDocument.Sections[j].Range.Editors.Item(i)....
                }
            }
于 2013-11-01T12:26:43.357 回答