2013-05-20 121 views
0

我的工具将处理超过1000个文档。我们在文档级别设置了Readonly,导致严重的性能问题。
_appObject = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document _DocObj; string file = @“c:\ Users \ Public \ Public Documents \ Word12.docx”;
_DocObj = _appObject.Documents.Open(参考文件,REF缺失,REF缺失,REF缺失,
REF缺失,REF缺失,REF缺失,REF缺失,REF缺失,REF缺失,裁判
缺失,REF缺失,裁判失踪,裁判失踪,裁判失踪); // protect
appObject.ActiveDocument.Protect(Microsoft.Office.Interop.Word.WdProtectionType .wdAllowOnly Reading,ref noReset,ref password,ref useIRM,ref enforceStyleLock);C#以段落或范围级别只读保护word文档

但我想使段落或范围为只读

foreach (Microsoft.Office.Interop.Word.Paragraph aPar in 
        _appObject.ActiveDocument.Paragraphs) 
{ 
Microsoft.Office.Interop.Word.Range parRng = aPar.Range; 
string sText = parRng.Text; 
// I want to make readonly here 
} 

那么文档将得到保存。

_DocObj.SaveAs(FileName: TargetDir, FileFormat: WdSaveFormat.wdFormatDocumentDefault); 
      object saveChanges = WdSaveOptions.wdSaveChanges; 
      object originalFormat = WdOriginalFormat.wdOriginalDocumentFormat; 
      object routeDocument = true; 
      islockStatus = true; 
var doc_close = (Microsoft.Office.Interop.Word._Document)_DocObj; 
doc_close.Close(ref saveChanges, ref originalFormat, ref routeDocument); 

因此,要求是这样的,以使字文件(特别是标题或段落或alteast范围)

回答

0

的一部分。如果你有Range对象,则可以使用Editors构件来访问列表允许编辑该范围的用户。

对于您的情况,您希望启用“everyone”来编辑整个文档,然后删除编辑特定段落的权限。

在VBA中,这将是这个样子(我相信你能翻译这对C#):

' Allow access to the entire doc 
ActiveDocument.Content.Editors.Add wdEditorEveryone 

' Remove access to paragraph 1 
ActiveDocument.Content.Paragraphs(1).Editors(wdEditorEveryone).Delete