zoukankan      html  css  js  c++  java
  • c# word interop encrypt with password protect with password

    		public static void EncryptWithPassword(string unEncryptedWordPath, string password)
    		{
    			Word.Application wordApp = null;
    			Word.Document document = null;
    
    			try
    			{
    				object missung = System.Type.Missing;
    				object odocPath = unEncryptedWordPath;
    				object opassword = password;
    			
    				wordApp = new Word.Application();
    				document = wordApp.Documents.Open(odocPath);
    				document.Password = password;
    				document.SaveAs(ref odocPath, Word.WdSaveFormat.wdFormatDocumentDefault);
    			}
    			catch (Exception e)
    			{
    				string s = e.ToString();
    				Console.WriteLine(s);
    				throw;
    			}
    			finally
    			{
    				Quit(wordApp, document);
    			}
    		}
    
    
    
    
            public static void Quit(Word._Application wordApp, Word._Document doc)
            {
    			if(doc != null)
    				((Word._Document)doc).Close(Word.WdSaveOptions.wdDoNotSaveChanges);
    			object ofalse = false;
    			//ref false   to prevent the Word Process Hang in Task Manager
    			if(wordApp !=null && wordApp.Application != null)
    				((Word._Application)wordApp.Application).Quit(ref ofalse, ref ofalse, ref ofalse);
            }
    

      

  • 相关阅读:
    转:深入 AngularUI Router
    angularJS $scope的$apply方法实现model刷新
    CSS 如何让 height:100%; 起作用
    【AngularJs】---$sce 输出Html
    angular 组件之间传值
    kendo Grid 列添加自定义模板
    关于“内控点”
    关于总结
    咏春
    一只老鼠夹
  • 原文地址:https://www.cnblogs.com/wwwblender-3dcn/p/10205469.html
Copyright © 2011-2022 走看看