当前位置: 移动技术网 > IT编程>开发语言>.net > c# word interop encrypt with password protect with password

c# word interop encrypt with password protect with password

2019年01月03日  | 移动技术网IT编程  | 我要评论

傅作义简介,22216轴承,2011sbs歌谣大战节目单

		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);
        }

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网