private GetFooterByType ( string type ) : |
||
type | string | |
return |
private static void PopulateDocument(DocX document, Package package) { Headers headers = new Headers(); headers.odd = document.GetHeaderByType("default"); headers.even = document.GetHeaderByType("even"); headers.first = document.GetHeaderByType("first"); Footers footers = new Footers(); footers.odd = document.GetFooterByType("default"); footers.even = document.GetFooterByType("even"); footers.first = document.GetFooterByType("first"); //// Get the sectPr for this document. //XElement sect = document.mainDoc.Descendants(XName.Get("sectPr", DocX.w.NamespaceName)).Single(); //if (sectPr != null) //{ // // Extract the even header reference // var header_even_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "headerReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "even"); // string id = header_even_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res = document.mainPart.GetRelationship(id); // string ans = res.SourceUri.OriginalString; // headers.even.xml_filename = ans; // // Extract the odd header reference // var header_odd_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "headerReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "default"); // string id2 = header_odd_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res2 = document.mainPart.GetRelationship(id2); // string ans2 = res2.SourceUri.OriginalString; // headers.odd.xml_filename = ans2; // // Extract the first header reference // var header_first_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "h //eaderReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "first"); // string id3 = header_first_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res3 = document.mainPart.GetRelationship(id3); // string ans3 = res3.SourceUri.OriginalString; // headers.first.xml_filename = ans3; // // Extract the even footer reference // var footer_even_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "footerReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "even"); // string id4 = footer_even_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res4 = document.mainPart.GetRelationship(id4); // string ans4 = res4.SourceUri.OriginalString; // footers.even.xml_filename = ans4; // // Extract the odd footer reference // var footer_odd_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "footerReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "default"); // string id5 = footer_odd_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res5 = document.mainPart.GetRelationship(id5); // string ans5 = res5.SourceUri.OriginalString; // footers.odd.xml_filename = ans5; // // Extract the first footer reference // var footer_first_ref = sectPr.Elements().SingleOrDefault(x => x.Name.LocalName == "footerReference" && x.Attribute(XName.Get("type", DocX.w.NamespaceName)) != null && x.Attribute(XName.Get("type", DocX.w.NamespaceName)).Value == "first"); // string id6 = footer_first_ref.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value; // var res6 = document.mainPart.GetRelationship(id6); // string ans6 = res6.SourceUri.OriginalString; // footers.first.xml_filename = ans6; //} document.Xml = document.mainDoc.Root.Element(w + "body"); document.headers = headers; document.footers = footers; document.settingsPart = HelperFunctions.CreateOrGetSettingsPart(package); var ps = package.GetParts(); //document.endnotesPart = HelperFunctions.GetPart(); foreach (var rel in document.mainPart.GetRelationships()) { switch (rel.RelationshipType) { case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes": document.endnotesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.endnotesPart.GetStream())) document.endnotes = XDocument.Load(tr); break; case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes": document.footnotesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.footnotesPart.GetStream())) document.footnotes = XDocument.Load(tr); break; case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles": document.stylesPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.stylesPart.GetStream())) document.styles = XDocument.Load(tr); break; case "http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects": document.stylesWithEffectsPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.stylesWithEffectsPart.GetStream())) document.stylesWithEffects = XDocument.Load(tr); break; case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable": document.fontTablePart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.fontTablePart.GetStream())) document.fontTable = XDocument.Load(tr); break; case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering": document.numberingPart = package.GetPart(new Uri("/word/" + rel.TargetUri.OriginalString.Replace("/word/", ""), UriKind.Relative)); using (TextReader tr = new StreamReader(document.numberingPart.GetStream())) document.numbering = XDocument.Load(tr); break; default: break; } } }