簡體   English   中英

使用 OpenXML 打開受保護的 word 文檔

[英]Open protected word document with OpenXML

我到處搜索,但找不到任何答案。 所有帖子和討論都是關於創建受保護的,但與打開它無關。

我在我的 c# 程序中保護了 DOCX 和 DOC 文檔,並希望使用 OpenXML 2.5 以編程方式打開它們。

我使用 Office interlope 打開它們,因為它有密碼參數。 但是對於大文件數量來說它非常慢。

我可以使用 OpenXml 打開受密碼保護的 word 文檔嗎? 如何?

謝謝。

受密碼保護的文檔(使用密碼保存的文檔)不是 Zip 包,它們是二進制文件。 仔細想想,原因很明顯:XML 文件的 Zip 包是人類可讀的——不安全。 因此,您無法通過 Open XML 文件格式操作受密碼保護的 Word 文檔 - 它根本不存在。

有一種方法可以通過取消保護來使用OpenXml釋放 這里找到答案。

WordprocessingDocument doc = WordprocessingDocument.Open(filePaths[i], true);
doc.ExtendedFilePropertiesPart.Properties.DocumentSecurity = new DocumentSecurity("0");
doc.ExtendedFilePropertiesPart.Properties.Save();
DocumentFormat.OpenXml.Wordprocessing.DocumentProtection dp =
doc.MainDocumentPart.DocumentSettingsPart
.Settings.ChildElements.First<DocumentFormat.OpenXml.Wordprocessing.DocumentProtection>();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM