本文整理汇总了C#中DocumentFormat.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentFormat.InsertBefore方法的具体用法?C# DocumentFormat.InsertBefore怎么用?C# DocumentFormat.InsertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentFormat
的用法示例。
在下文中一共展示了DocumentFormat.InsertBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCommentOnParagraph
//Добавление комментария
public void AddCommentOnParagraph(DocumentFormat.OpenXml.Wordprocessing.Paragraph comPar, string comment)
{
DocumentFormat.OpenXml.Wordprocessing.Comments comments = null;
string id = "0";
// Verify that the document contains a
// WordProcessingCommentsPart part; if not, add a new one.
if (document.MainDocumentPart.GetPartsCountOfType<WordprocessingCommentsPart>() > 0)
{
comments =
document.MainDocumentPart.WordprocessingCommentsPart.Comments;
if (comments.HasChildren == true)
{
// Obtain an unused ID.
id = comments.Descendants<DocumentFormat.OpenXml.Wordprocessing.Comment>().Select(e => e.Id.Value).Max() + 1;
}
}
else
{
// No WordprocessingCommentsPart part exists, so add one to the package.
WordprocessingCommentsPart commentPart = document.MainDocumentPart.AddNewPart<WordprocessingCommentsPart>();
commentPart.Comments = new DocumentFormat.OpenXml.Wordprocessing.Comments();
comments = commentPart.Comments;
}
// Compose a new Comment and add it to the Comments part.
DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new Text(comment)));
DocumentFormat.OpenXml.Wordprocessing.Comment cmt =
new DocumentFormat.OpenXml.Wordprocessing.Comment()
{
Id = id,
Author = "FRChecking System",
Date = DateTime.Now
};
cmt.AppendChild(p);
comments.AppendChild(cmt);
comments.Save();
// Specify the text range for the Comment.
// Insert the new CommentRangeStart before the first run of paragraph.
comPar.InsertBefore(new CommentRangeStart() { Id = id }, comPar.GetFirstChild<DocumentFormat.OpenXml.Wordprocessing.Run>());
// Insert the new CommentRangeEnd after last run of paragraph.
var cmtEnd = comPar.InsertAfter(new CommentRangeEnd() { Id = id }, comPar.Elements<DocumentFormat.OpenXml.Wordprocessing.Run>().Last());
// Compose a run with CommentReference and insert it.
comPar.InsertAfter(new DocumentFormat.OpenXml.Wordprocessing.Run(new CommentReference() { Id = id }), cmtEnd);
}