原創|使用教程|編輯:胡濤|2023-04-06 11:37:28.960|閱讀 125 次
概述:本文我們將演示如何鎖定標題信息以防止編輯。我們將把它分成兩部分進行演示。一次是用header鎖定已有word文檔的header信息,一次是在新建的word文檔上。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在 Spire.Doc 的幫助下,我們可以輕松地在 C# 中為 word 文檔和本文我們將演示如何鎖定標題信息以防止編輯。我們將把它分成兩部分進行演示。一次是用header鎖定已有word文檔的header信息,一次是在新建的word文檔上。
如何鎖定現有word文檔的頁眉信息。
//Load the sample document with header<font></font> Document doc = new Document();<font></font> doc.LoadFromFile("sample.docx");<font></font> <font></font> //Get the first section from the word document<font></font> Section section = doc.Sections[0];<font></font> <font></font> //Protect the document and set the ProtectionType as AllowOnlyFormFields<font></font> doc.Protect(ProtectionType.AllowOnlyFormFields, "123");<font></font> <font></font> //Set the ProtectForm as false to unprotect the section<font></font> section.ProtectForm = false;<font></font> <font></font> //Save the document to file<font></font> doc.SaveToFile("Result.docx", FileFormat.Docx2013);<font></font>
頭部有效截圖已鎖定,其他區域可編輯:
如何鎖定新建word文檔的頁眉信息。
//Create a new instance of word document<font></font> Document doc = new Document();<font></font> <font></font> //Add a section to the word document<font></font> Section section = doc.AddSection();<font></font> <font></font> //Add header information to the section<font></font> HeaderFooter header = section.HeadersFooters.Header;<font></font> Paragraph HParagraph = header.AddParagraph();<font></font> TextRange HText = HParagraph.AppendText("Protect header");<font></font> <font></font> //Add a paragraph to the section<font></font> Paragraph Para = section.AddParagraph();<font></font> Para.AppendText("Demo of how to lock the header information by Spire.Doc ");<font></font> <font></font> //Set the ProtectionType as AllowOnlyFormFields and then unprotect the section<font></font> doc.Protect(ProtectionType.AllowOnlyFormFields, "123");<font></font> section.ProtectForm = false;<font></font> <font></font> //Save the document to file<font></font> doc.SaveToFile("Result.docx", FileFormat.Docx2013);<font></font>
以上便如鎖定標題以防止在 C# 中編輯 word 文檔,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn