本文整理汇总了C#中Body.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# Body.InsertBefore方法的具体用法?C# Body.InsertBefore怎么用?C# Body.InsertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body.InsertBefore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPageEnd
private static void AddPageEnd(Body wordBody, int i, SectionProperties bodySectionp)
{
//<w:br w:type="page" />
Paragraph lastParagraph = new Paragraph();
lastParagraph.AppendChild<BookmarkStart>(new BookmarkStart() { Id = new StringValue(i.ToString()), Name = "_GoBack" });
lastParagraph.AppendChild<BookmarkEnd>(new BookmarkEnd() { Id = new StringValue(i.ToString()) });
lastParagraph.AppendChild<Run>(new Run(new Break() { Type = BreakValues.Page }));
//lastParagraph.AppendChild<LastRenderedPageBreak>(new LastRenderedPageBreak());
wordBody.InsertBefore<OpenXmlElement>(lastParagraph, bodySectionp);
}
示例2: ValidateBody
//.........这里部分代码省略.........
Assert.True(actual.Valid);
body.InsertAfter(new Paragraph(), body.FirstChild);
target.Validate(validationContext);
Assert.True(actual.Valid);
body.PrependChild(new MoveFromRangeStart());
target.Validate(validationContext);
Assert.True(actual.Valid);
body.PrependChild(new MoveFromRun());
target.Validate(validationContext);
Assert.True(actual.Valid);
//body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
//target.Validate(validationContext);
//Assert.True(actual.Valid);
//body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
//target.Validate(validationContext);
//Assert.True(actual.Valid);
body.PrependChild(new MoveFromRun());
target.Validate(validationContext);
Assert.True(actual.Valid);
body.PrependChild(new MoveFromRangeStart());
target.Validate(validationContext);
Assert.True(actual.Valid);
body.InsertAfter(new Paragraph(), body.FirstChild);
target.Validate(validationContext);
Assert.True(actual.Valid);
// ***** error case ******
// sectProperties can not be the first
errorChild = body.FirstChild;
body.PrependChild(new SectionProperties());
target.Validate(validationContext);
Assert.False(actual.Valid);
Assert.Equal(1, actual.Errors.Count);
Assert.Same(expected, actual.Errors[0].Node);
Assert.Same(errorChild, actual.Errors[0].RelatedNode);
Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
body.RemoveChild(body.FirstChild);
actual.Clear();
// can only have one sectProperties at last
errorChild = body.AppendChild(new SectionProperties());
target.Validate(validationContext);
Assert.False(actual.Valid);
Assert.Equal(1, actual.Errors.Count);
Assert.Same(expected, actual.Errors[0].Node);
Assert.Same(errorChild, actual.Errors[0].RelatedNode);
Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
body.RemoveChild(errorChild);
actual.Clear();
// paragrap can be after sectProperties at last
errorChild = body.AppendChild(new Paragraph());
target.Validate(validationContext);
Assert.False(actual.Valid);
Assert.Equal(1, actual.Errors.Count);
Assert.Same(expected, actual.Errors[0].Node);
Assert.Same(errorChild, actual.Errors[0].RelatedNode);
Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
body.RemoveChild(errorChild);
actual.Clear();
// first is invalid
errorChild = body.PrependChild(new Run());
target.Validate(validationContext);
Assert.False(actual.Valid);
Assert.Equal(1, actual.Errors.Count);
Assert.Same(expected, actual.Errors[0].Node);
Assert.Same(errorChild, actual.Errors[0].RelatedNode);
Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
Assert.True(actual.Errors[0].Description.Contains(":altChunk"));
body.RemoveChild(errorChild);
actual.Clear();
// invalid child in middle
errorChild = body.InsertBefore(new Run(), body.LastChild);
target.Validate(validationContext);
Assert.False(actual.Valid);
Assert.Equal(1, actual.Errors.Count);
Assert.Same(expected, actual.Errors[0].Node);
Assert.Same(errorChild, actual.Errors[0].RelatedNode);
Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
body.RemoveChild(errorChild);
}