[英]How to get the range of first paragraph on each page in Word Document using C# Word interlop
[英]C# programatically protect word document readonly at paragraph or range level
我的工具将处理1000多个文档。 我们在文档级别设置了只读,这会导致严重的性能问题。
_appObject =新的Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document _DocObj; 字符串文件= @“ c:\\ Users \\ Public \\ Public Documents \\ Word12.docx”;
_DocObj = _appObject.Documents.Open(参考文件,参考缺失,参考缺失,参考缺失,
裁判缺失,裁判缺失,裁判缺失,裁判缺失,裁判缺失,裁判缺失,裁判
缺少,裁判缺失,裁判缺失,裁判缺失,裁判缺失); //保护
appObject.ActiveDocument.Protect(Microsoft.Office.Interop.Word.WdProtectionType .wdAllowOnly阅读,ref noReset,ref密码,ref useIRM,refforceStyleStyleLock);
但我想将段落或范围设为只读
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);
因此,要求就像制作Word文档的一部分(尤其是HEADING或段落或其他范围)
如果有Range
对象,则可以使用Editors
成员访问允许编辑该范围的用户列表。
对于您的情况,您需要启用“所有人”来编辑整个文档,然后删除编辑特定段落的权限。
在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.