我的工具将处理超过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范围)