问题描述
- C#调用Permission实现对office文档权限设置
-
C#添加Microsoft.Office.Core组件,调用Permission实现对office文档权限设置,调用permission.Add(string userid, property, expirationTime)时,expirationTime设置无效,格式为:
object expirationTime;
DateTime testtime=DateTime.ParseExact("2015/12/26","yyyy/MM/d",System.Globalization.CultureInfo.InvariantCulture);expirationTime = (object)testtime;
欲将时间期限设置为2015/12/26,但效果是文档的读写权限设置成功,时间设置不起作用。跪求正确的时间格式啊
解决方案
https://technet.microsoft.com/zh-cn/library/cc179103.aspx
解决方案二:
这是我的代码:
object MYNOTHING = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document book;
Microsoft.Office.Interop.Word.Application m_woapp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document book = m_wobooks.Open(filepath, MsoTriState.msoFalse, OBFALSE, OBFALSE, MYNOTHING, MYNOTHING, MYNOTHING,MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING, MYNOTHING);
Microsoft.Office.Core.Permission permission = book.Permission;
object expirationTime;
DateTime testtime = DateTime.ParseExact("2015/12/26", "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture);
expirationTime = (object)testtime;
permission.Add("user@.com", MsoPermission.msoPermissionChange, expirationTime);
不报错,读写权限设置成功了,但expirationTime没起作用,急求时间写法啊