本文整理汇总了C#中OpenXmlPart.PutXDocument方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart.PutXDocument方法的具体用法?C# OpenXmlPart.PutXDocument怎么用?C# OpenXmlPart.PutXDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlPart
的用法示例。
在下文中一共展示了OpenXmlPart.PutXDocument方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessTemplatePart
private static void ProcessTemplatePart(XElement data, TemplateError te, OpenXmlPart part)
{
XDocument xDoc = part.GetXDocument();
XElement newRootElementWithMetadata = (XElement)TransformToMetadata(xDoc.Root, data, te);
NormalizeTablesRepeatAndConditional(newRootElementWithMetadata, te);
XElement newRootElement = newRootElementWithMetadata;
// do the actual content replacement
newRootElement = (XElement)ContentReplacementTransform(newRootElement, data, te);
xDoc.Elements().First().ReplaceWith(newRootElement);
part.PutXDocument();
return;
}
示例2: MergeCommentsInPart
private static void MergeCommentsInPart(OpenXmlPart part1, OpenXmlPart part2,
OpenXmlPart destinationPart, XDocument commentsPartXDoc)
{
XDocument xdoc1 = part1.GetXDocument();
XDocument xdoc2 = part2.GetXDocument();
XElement newRootElement = (XElement)MergeElementTransform(xdoc1.Root, xdoc2.Root,
commentsPartXDoc);
destinationPart.PutXDocument(new XDocument(newRootElement));
}
示例3: AcceptRevisionsForPart
private static void AcceptRevisionsForPart(OpenXmlPart part)
{
XElement documentElement = part.GetXDocument().Root;
documentElement = (XElement)AcceptMoveFromMoveToTransform(documentElement);
documentElement = AcceptMoveFromRanges(documentElement);
// AcceptParagraphEndTagsInMoveFromTransform needs rewritten similar to AcceptDeletedAndMoveFromParagraphMarks
documentElement = (XElement)AcceptParagraphEndTagsInMoveFromTransform(documentElement);
documentElement = AcceptDeletedAndMovedFromContentControls(documentElement);
documentElement = AcceptDeletedAndMoveFromParagraphMarks(documentElement);
documentElement = (XElement)AcceptAllOtherRevisionsTransform(documentElement);
documentElement = (XElement)AcceptDeletedCellsTransform(documentElement);
documentElement.Descendants().Attributes().Where(a => a.Name == PT.UniqueId || a.Name == PT.RunIds).Remove();
XDocument newXDoc = new XDocument(documentElement);
part.PutXDocument(newXDoc);
}
示例4: SimplifyMarkupForPart
//.........这里部分代码省略.........
WordprocessingDocument doc = (WordprocessingDocument)part.OpenXmlPackage;
if (settings.RemoveGoBackBookmark == true)
{
var goBackBookmark = doc
.MainDocumentPart
.GetXDocument()
.Root
.Descendants(W.bookmarkStart)
.FirstOrDefault(bm => (string)bm.Attribute(W.name) == "_GoBack");
if (goBackBookmark != null)
parameters.GoBackId = (int)goBackBookmark.Attribute(W.id);
}
}
XDocument xdoc = part.GetXDocument();
XElement newRoot = xdoc.Root;
// Need to do this first to enable simplifying hyperlinks.
if (settings.RemoveContentControls ||
settings.RemoveSmartTags)
newRoot = (XElement)
RemoveCustomXmlAndContentControlsTransform(
newRoot, settings);
// This may touch many elements, so needs to be its own
// transform.
if (settings.RemoveRsidInfo)
newRoot = (XElement)RemoveRsidTransform(newRoot);
XDocument prevNewRoot = new XDocument(newRoot);
while (true)
{
if (settings.RemoveComments ||
settings.RemoveEndAndFootNotes ||
settings.ReplaceTabsWithSpaces ||
settings.RemoveFieldCodes ||
settings.RemovePermissions ||
settings.RemoveProof ||
settings.RemoveBookmarks ||
settings.RemoveWebHidden ||
settings.RemoveGoBackBookmark)
newRoot = (XElement)SimplifyMarkupTransform(newRoot,
settings, parameters);
// Remove runs and run properties that have become empty due to previous
// transforms.
newRoot = (XElement)
RemoveEmptyRunsAndRunPropertiesTransform(newRoot);
// Merge adjacent runs that have identical run properties.
newRoot = (XElement)MergeAdjacentRunsTransform(newRoot);
// Merge adjacent instrText elements.
newRoot = (XElement)MergeAdjacentInstrText(newRoot);
// Separate run children into separate runs
newRoot = (XElement)SeparateRunChildrenIntoSeparateRuns(newRoot);
if (XNode.DeepEquals(prevNewRoot.Root, newRoot))
break;
prevNewRoot = new XDocument(newRoot);
}
if (settings.NormalizeXml)
{
XAttribute[] ns_attrs =
{
new XAttribute(XNamespace.Xmlns + "wpc", WPC.wpc),
new XAttribute(XNamespace.Xmlns + "mc", MC.mc),
new XAttribute(XNamespace.Xmlns + "o", O.o),
new XAttribute(XNamespace.Xmlns + "r", R.r),
new XAttribute(XNamespace.Xmlns + "m", M.m),
new XAttribute(XNamespace.Xmlns + "v", VML.vml),
new XAttribute(XNamespace.Xmlns + "wp14", WP14.wp14),
new XAttribute(XNamespace.Xmlns + "wp", WP.wp),
new XAttribute(XNamespace.Xmlns + "w10", W10.w10),
new XAttribute(XNamespace.Xmlns + "w", W.w),
new XAttribute(XNamespace.Xmlns + "w14", W14.w14),
new XAttribute(XNamespace.Xmlns + "wpg", WPG.wpg),
new XAttribute(XNamespace.Xmlns + "wpi", WPI.wpi),
new XAttribute(XNamespace.Xmlns + "wne", WNE.wne),
new XAttribute(XNamespace.Xmlns + "wps", WPS.wps),
new XAttribute(MC.Ignorable, "w14 wp14"),
};
XDocument newXDoc = Normalize(new XDocument(newRoot), null);
foreach (var nsatt in ns_attrs)
{
if (newXDoc.Root.Attribute(nsatt.Name) == null)
newXDoc.Root.Add(nsatt);
}
part.PutXDocument(newXDoc);
}
else
{
part.PutXDocument(new XDocument(newRoot));
}
}
示例5: SimplifyMarkupForPart
private static void SimplifyMarkupForPart(
OpenXmlPart part,
SimplifyMarkupSettings settings)
{
XDocument xdoc = part.GetXDocument();
XElement newRoot = xdoc.Root;
// Need to do this first to enable simplifying hyperlinks.
if (settings.RemoveContentControls ||
settings.RemoveSmartTags)
newRoot = (XElement)
RemoveCustomXmlAndContentControlsTransform(
newRoot, settings);
// This may touch many elements, so needs to be its own
// transform.
if (settings.RemoveRsidInfo)
newRoot = (XElement)RemoveRsidTransform(newRoot);
if (settings.RemoveComments ||
settings.RemoveEndAndFootNotes ||
settings.ReplaceTabsWithSpaces ||
settings.RemoveFieldCodes ||
settings.RemovePermissions ||
settings.RemoveProof ||
settings.RemoveBookmarks ||
settings.RemoveWebHidden)
newRoot = (XElement)SimplifyMarkupTransform(newRoot,
settings);
// Remove runs and run properties that have become empty due to previous
// transforms.
newRoot = (XElement)
RemoveEmptyRunsAndRunPropertiesTransform(newRoot);
// Merge adjacent runs that have identical run properties.
newRoot = (XElement)RemoveSuperfluousRunsTransform(newRoot);
// Merge adjacent instrText elements.
newRoot = (XElement)MergeAdjacentInstrText(newRoot);
// The last thing to do is to again remove runs and run properties
// that have become empty due to previous transforms.
newRoot = (XElement)
RemoveEmptyRunsAndRunPropertiesTransform(newRoot);
if (settings.NormalizeXml)
{
XAttribute[] ns_attrs =
{
new XAttribute(XNamespace.Xmlns + "wpc", WPC.wpc),
new XAttribute(XNamespace.Xmlns + "mc", MC.mc),
new XAttribute(XNamespace.Xmlns + "o", O.o),
new XAttribute(XNamespace.Xmlns + "r", R.r),
new XAttribute(XNamespace.Xmlns + "m", M.m),
new XAttribute(XNamespace.Xmlns + "v", VML.vml),
new XAttribute(XNamespace.Xmlns + "wp14", WP14.wp14),
new XAttribute(XNamespace.Xmlns + "wp", WP.wp),
new XAttribute(XNamespace.Xmlns + "w10", W10.w10),
new XAttribute(XNamespace.Xmlns + "w", W.w),
new XAttribute(XNamespace.Xmlns + "w14", W14.w14),
new XAttribute(XNamespace.Xmlns + "wpg", WPG.wpg),
new XAttribute(XNamespace.Xmlns + "wpi", WPI.wpi),
new XAttribute(XNamespace.Xmlns + "wne", WNE.wne),
new XAttribute(XNamespace.Xmlns + "wps", WPS.wps),
new XAttribute(MC.Ignorable, "w14 wp14"),
};
XDocument newXDoc = Normalize(new XDocument(newRoot), null);
newXDoc.Root.Add(ns_attrs);
part.PutXDocument(newXDoc);
}
else
{
part.PutXDocument(new XDocument(newRoot));
}
}
示例6: UpdatePartForToa
private static void UpdatePartForToa(OpenXmlPart part)
{
XDocument xDoc = part.GetXDocument();
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "TableofAuthorities")
.FirstOrDefault(),
@"<w:style w:type='paragraph'
w:styleId='TableofAuthorities'
xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='table of authorities'/>
<w:basedOn w:val='Normal'/>
<w:next w:val='Normal'/>
<w:uiPriority w:val='99'/>
<w:semiHidden/>
<w:unhideWhenUsed/>
<w:rsid w:val='0090569D'/>
<w:pPr>
<w:spacing w:after='0'/>
<w:ind w:left='220'
w:hanging='220'/>
</w:pPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "TOAHeading")
.FirstOrDefault(),
@"<w:style w:type='paragraph'
w:styleId='TOAHeading'
xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='toa heading'/>
<w:basedOn w:val='Normal'/>
<w:next w:val='Normal'/>
<w:uiPriority w:val='99'/>
<w:semiHidden/>
<w:unhideWhenUsed/>
<w:rsid w:val='0090569D'/>
<w:pPr>
<w:spacing w:before='120'/>
</w:pPr>
<w:rPr>
<w:rFonts w:asciiTheme='majorHAnsi'
w:eastAsiaTheme='majorEastAsia'
w:hAnsiTheme='majorHAnsi'
w:cstheme='majorBidi'/>
<w:b/>
<w:bCs/>
<w:sz w:val='24'/>
<w:szCs w:val='24'/>
</w:rPr>
</w:style>");
part.PutXDocument();
}
示例7: UpdatePartForTof
private static void UpdatePartForTof(OpenXmlPart part)
{
XDocument xDoc = part.GetXDocument();
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "TableofFigures")
.FirstOrDefault(),
@"<w:style w:type='paragraph' w:styleId='TableofFigures' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='table of figures'/>
<w:basedOn w:val='Normal'/>
<w:next w:val='Normal'/>
<w:uiPriority w:val='99'/>
<w:unhideWhenUsed/>
<w:pPr>
<w:spacing w:after='0'/>
</w:pPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "character" && (string)e.Attribute(W.styleId) == "Hyperlink")
.FirstOrDefault(),
@"<w:style w:type='character' w:styleId='Hyperlink' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='Hyperlink'/>
<w:basedOn w:val='DefaultParagraphFont'/>
<w:uiPriority w:val='99'/>
<w:unhideWhenUsed/>
<w:rPr>
<w:color w:val='0000FF' w:themeColor='hyperlink'/>
<w:u w:val='single'/>
</w:rPr>
</w:style>");
part.PutXDocument();
}
示例8: UpdatePartForToc
//.........这里部分代码省略.........
<w:spacing w:after='100'/>
<w:ind w:left='220'/>
</w:pPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "TOC3")
.FirstOrDefault(),
@"<w:style w:type='paragraph' w:styleId='TOC3' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='toc 3'/>
<w:basedOn w:val='Normal'/>
<w:next w:val='Normal'/>
<w:autoRedefine/>
<w:uiPriority w:val='39'/>
<w:unhideWhenUsed/>
<w:pPr>
<w:spacing w:after='100'/>
<w:ind w:left='440'/>
</w:pPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "TOC4")
.FirstOrDefault(),
@"<w:style w:type='paragraph' w:styleId='TOC4' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='toc 4'/>
<w:basedOn w:val='Normal'/>
<w:next w:val='Normal'/>
<w:autoRedefine/>
<w:uiPriority w:val='39'/>
<w:unhideWhenUsed/>
<w:pPr>
<w:spacing w:after='100'/>
<w:ind w:left='660'/>
</w:pPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "character" && (string)e.Attribute(W.styleId) == "Hyperlink")
.FirstOrDefault(),
@"<w:style w:type='character' w:styleId='Hyperlink' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='Hyperlink'/>
<w:basedOn w:val='DefaultParagraphFont'/>
<w:uiPriority w:val='99'/>
<w:unhideWhenUsed/>
<w:rPr>
<w:color w:val='0000FF' w:themeColor='hyperlink'/>
<w:u w:val='single'/>
</w:rPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "paragraph" && (string)e.Attribute(W.styleId) == "BalloonText")
.FirstOrDefault(),
@"<w:style w:type='paragraph' w:styleId='BalloonText' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='Balloon Text'/>
<w:basedOn w:val='Normal'/>
<w:link w:val='BalloonTextChar'/>
<w:uiPriority w:val='99'/>
<w:semiHidden/>
<w:unhideWhenUsed/>
<w:pPr>
<w:spacing w:after='0' w:line='240' w:lineRule='auto'/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii='Tahoma' w:hAnsi='Tahoma' w:cs='Tahoma'/>
<w:sz w:val='16'/>
<w:szCs w:val='16'/>
</w:rPr>
</w:style>");
AddElementIfMissing(
xDoc,
xDoc.Root.Elements(W.style)
.Where(e => (string)e.Attribute(W.type) == "character" &&
(bool?)e.Attribute(W.customStyle) == true && (string)e.Attribute(W.styleId) == "BalloonTextChar")
.FirstOrDefault(),
@"<w:style w:type='character' w:customStyle='1' w:styleId='BalloonTextChar' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:name w:val='Balloon Text Char'/>
<w:basedOn w:val='DefaultParagraphFont'/>
<w:link w:val='BalloonText'/>
<w:uiPriority w:val='99'/>
<w:semiHidden/>
<w:rPr>
<w:rFonts w:ascii='Tahoma' w:hAnsi='Tahoma' w:cs='Tahoma'/>
<w:sz w:val='16'/>
<w:szCs w:val='16'/>
</w:rPr>
</w:style>");
part.PutXDocument();
}
示例9: TransformPartToSingleCharacterRuns
public static void TransformPartToSingleCharacterRuns(OpenXmlPart part)
{
// After transforming to single character runs, Rsid info will be invalid, so
// remove from the part.
XDocument xDoc = part.GetXDocument();
XElement newRoot = (XElement)RemoveRsidTransform(xDoc.Root);
newRoot = (XElement)SingleCharacterRunTransform(newRoot);
xDoc.Elements().First().ReplaceWith(newRoot);
part.PutXDocument();
}