本文整理汇总了C#中Novacode.DocX.GetHeaderByType方法的典型用法代码示例。如果您正苦于以下问题:C# DocX.GetHeaderByType方法的具体用法?C# DocX.GetHeaderByType怎么用?C# DocX.GetHeaderByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Novacode.DocX
的用法示例。
在下文中一共展示了DocX.GetHeaderByType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateDocument
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":
//.........这里部分代码省略.........