private static IEnumerable<BookmarkStart> GetAllBookmarks(OpenXmlPartRootElement rootElement) { var allBookmarks = rootElement.Descendants<BookmarkStart>(); if (allBookmarks == null) { throw new InvalidOperationException("There were no bookmarks found in the source document."); } return allBookmarks; }
/// <summary> /// Get the part in which the element is in. /// </summary> /// <param name="element">The element.</param> /// <returns>The part in which the element is in. Returns null if not in a part.</returns> internal static OpenXmlPart GetPart(this OpenXmlElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } OpenXmlPartRootElement partRootElement = element.GetPartRootElement(); if (partRootElement != null && partRootElement.OpenXmlPart != null) { return(partRootElement.OpenXmlPart); } return(null); }
private static void AddHeaderFooterNamespaceDeclaration(OpenXmlPartRootElement headerFooter) { headerFooter.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"); headerFooter.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); headerFooter.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office"); headerFooter.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); headerFooter.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"); headerFooter.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml"); headerFooter.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"); headerFooter.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); headerFooter.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word"); headerFooter.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); headerFooter.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); headerFooter.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"); headerFooter.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"); headerFooter.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml"); headerFooter.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"); }
private List<OpenXmlElement> GetDescendatsFilteredByType(OpenXmlPartRootElement rootElement) { return rootElement.Descendants().Where(x => x.IsAnyOfType<Paragraph, Table>()).ToList(); }