-1

我知道 C# 中有几种 docx 创建/修改方法

OpenXML、DocX API 等。

我已经想出了如何使用 Open XML 启用跟踪更改,只是还没有想出锁定跟踪更改(word 2013 中的一个功能)。

4

2 回答 2

1

这段代码对我来说很好:

static void Main(string[] args)
{
    using (var document = WordprocessingDocument.Open(@"D:\DocTest\Test1.docx", true))
    {
        AddTrackingLock(document);
    }
}

private static void AddTrackingLock(WordprocessingDocument document)
{
    var documentSettings = document.MainDocumentPart.DocumentSettingsPart;
    var documentProtection = documentSettings
                                .Settings
                                .FirstOrDefault(it =>
                                        it is DocumentProtection &&
                                        (it as DocumentProtection).Edit == DocumentProtectionValues.TrackedChanges)
                                as DocumentProtection;

    if (documentProtection == null)
    {
        var documentProtectionElement = new DocumentProtection();
        documentProtectionElement.Edit = DocumentProtectionValues.TrackedChanges;
        documentProtectionElement.Enforcement = OnOffValue.FromBoolean(true);
        documentSettings.Settings.AppendChild(documentProtectionElement);
    }
    else
    {
        documentProtection.Enforcement = OnOffValue.FromBoolean(true);
    }
}
于 2014-07-14T16:18:09.570 回答
1

查看如何使用 Open XML SDK 2.0 在 Word 中设置编辑限制

我没有任何工作代码给你,但密码哈希需要存储在 DocumentProtection.Hash. 希望这个提示能帮助你前进!

于 2014-07-21T13:06:33.330 回答