Reputation: 121
My tool will process more than 1000 docs. We had set Readonly at document level, which leads to severe performance issue.
_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 file, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing);
//protect
appObject.ActiveDocument.Protect(Microsoft.Office.Interop.Word.WdProtectionType
.wdAllowOnly Reading, ref noReset, ref password, ref useIRM, ref enforceStyleLock);
But I want to make the Paragraph or range to readonly
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
}
Then the doc will get saved.
_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);
Hence the requirement is like that to make a portion of word document (especially HEADING or paragraph or alteast range)
Upvotes: 0
Views: 2499
Reputation: 27516
If you have a Range
object, then you can use Editors
member to access the list of users that are allowed to edit that range.
In your case, you would want to enable "everyone" to edit the entire document, then remove permission to edit specific paragraphs.
In VBA, this would look something like this (I'm sure you can translate this to C#):
' Allow access to the entire doc
ActiveDocument.Content.Editors.Add wdEditorEveryone
' Remove access to paragraph 1
ActiveDocument.Content.Paragraphs(1).Editors(wdEditorEveryone).Delete
Upvotes: 0