当前位置: 首页>>代码示例>>C#>>正文


C# WordprocessingDocument.ContentParts方法代码示例

本文整理汇总了C#中WordprocessingDocument.ContentParts方法的典型用法代码示例。如果您正苦于以下问题:C# WordprocessingDocument.ContentParts方法的具体用法?C# WordprocessingDocument.ContentParts怎么用?C# WordprocessingDocument.ContentParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WordprocessingDocument的用法示例。


在下文中一共展示了WordprocessingDocument.ContentParts方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TransformToSingleCharacterRuns

 public static void TransformToSingleCharacterRuns(WordprocessingDocument doc)
 {
     if (RevisionAccepter.HasTrackedRevisions(doc))
         throw new OpenXmlPowerToolsException(
             "Transforming a document to single character runs is not supported for " +
             "a document with tracked revisions.");
     foreach (var part in doc.ContentParts())
         TransformPartToSingleCharacterRuns(part);
 }
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:9,代码来源:MarkupSimplifier.cs

示例2: SimplifyMarkup

 public static void SimplifyMarkup(WordprocessingDocument doc,
     SimplifyMarkupSettings settings)
 {
     if (settings.AcceptRevisions)
         RevisionAccepter.AcceptRevisions(doc);
     foreach (var part in doc.ContentParts())
         SimplifyMarkupForPart(part, settings);
     if (doc.MainDocumentPart.StyleDefinitionsPart != null)
         SimplifyMarkupForPart(doc.MainDocumentPart.StyleDefinitionsPart, settings);
     if (doc.MainDocumentPart.StylesWithEffectsPart != null)
         SimplifyMarkupForPart(doc.MainDocumentPart.StylesWithEffectsPart, settings);
 }
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:12,代码来源:MarkupSimplifier.cs

示例3: SimplifyMarkup

 public static void SimplifyMarkup(WordprocessingDocument doc,
     SimplifyMarkupSettings settings)
 {
     if (settings.RemoveMarkupForDocumentComparison)
     {
         settings.RemoveRsidInfo = true;
         RemoveElementsForDocumentComparison(doc);
     }
     if (settings.RemoveRsidInfo)
         RemoveRsidInfoInSettings(doc);
     if (settings.AcceptRevisions)
         RevisionAccepter.AcceptRevisions(doc);
     foreach (var part in doc.ContentParts())
         SimplifyMarkupForPart(part, settings);
     if (doc.MainDocumentPart.StyleDefinitionsPart != null)
         SimplifyMarkupForPart(doc.MainDocumentPart.StyleDefinitionsPart, settings);
     if (doc.MainDocumentPart.StylesWithEffectsPart != null)
         SimplifyMarkupForPart(doc.MainDocumentPart.StylesWithEffectsPart, settings);
 }
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:19,代码来源:MarkupSimplifier.cs

示例4: InsertAppropriateNonbreakingSpaces

 private static void InsertAppropriateNonbreakingSpaces(WordprocessingDocument wordDoc)
 {
     foreach (var part in wordDoc.ContentParts())
     {
         XDocument pxd = part.GetXDocument();
         XElement newRoot = (XElement)InsertAppropriateNonbreakingSpacesTransform(pxd.Root);
         pxd.Root.ReplaceWith(newRoot);
         part.PutXDocument();
     }
 }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:10,代码来源:HtmlConverter.cs

示例5: InsertAppropriateNonbreakingSpaces

        private static void InsertAppropriateNonbreakingSpaces(WordprocessingDocument wordDoc)
        {
            foreach (var part in wordDoc.ContentParts())
            {
                var pxd = part.GetXDocument();
                var root = pxd.Root;
                if (root == null) return;

                var newRoot = (XElement)InsertAppropriateNonbreakingSpacesTransform(root);
                root.ReplaceWith(newRoot);
                part.PutXDocument();
            }
        }
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:13,代码来源:HtmlConverter.cs

示例6: AssembleListItemInformation

 private static void AssembleListItemInformation(WordprocessingDocument wordDoc, ListItemRetrieverSettings settings)
 {
     foreach (var part in wordDoc.ContentParts())
     {
         XDocument xDoc = part.GetXDocument();
         foreach (var para in xDoc.Descendants(W.p))
         {
             ListItemRetriever.RetrieveListItem(wordDoc, para, settings);
         }
     }
 }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:11,代码来源:FormattingAssembler.cs

示例7: AssembleFormatting

 public static void AssembleFormatting(WordprocessingDocument wDoc, FormattingAssemblerSettings settings)
 {
     FormattingAssemblerInfo fai = new FormattingAssemblerInfo();
     XDocument sXDoc = wDoc.MainDocumentPart.StyleDefinitionsPart.GetXDocument();
     XElement defaultParagraphStyle = sXDoc
         .Root
         .Elements(W.style)
         .FirstOrDefault(st => st.Attribute(W._default).ToBoolean() == true &&
             (string)st.Attribute(W.type) == "paragraph");
     if (defaultParagraphStyle != null)
         fai.DefaultParagraphStyleName = (string)defaultParagraphStyle.Attribute(W.styleId);
     XElement defaultCharacterStyle = sXDoc
         .Root
         .Elements(W.style)
         .FirstOrDefault(st => st.Attribute(W._default).ToBoolean() == true &&
             (string)st.Attribute(W.type) == "character");
     if (defaultCharacterStyle != null)
         fai.DefaultCharacterStyleName = (string)defaultCharacterStyle.Attribute(W.styleId);
     XElement defaultTableStyle = sXDoc
         .Root
         .Elements(W.style)
         .FirstOrDefault(st => st.Attribute(W._default).ToBoolean() == true &&
             (string)st.Attribute(W.type) == "table");
     if (defaultTableStyle != null)
         fai.DefaultTableStyleName = (string)defaultTableStyle.Attribute(W.styleId);
     ListItemRetrieverSettings listItemRetrieverSettings = new ListItemRetrieverSettings();
     AssembleListItemInformation(wDoc, settings.ListItemRetrieverSettings);
     foreach (var part in wDoc.ContentParts())
     {
         var pxd = part.GetXDocument();
         FixNonconformantHexValues(pxd.Root);
         AnnotateWithGlobalDefaults(wDoc, pxd.Root, settings);
         AnnotateTablesWithTableStyles(wDoc, pxd.Root);
         AnnotateParagraphs(fai, wDoc, pxd.Root, settings);
         AnnotateRuns(fai, wDoc, pxd.Root, settings);
     }
     NormalizeListItems(fai, wDoc, settings);
     if (settings.ClearStyles)
         ClearStyles(wDoc);
     foreach (var part in wDoc.ContentParts())
     {
         var pxd = part.GetXDocument();
         pxd.Root.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration).Remove();
         FormattingAssembler.NormalizePropsForPart(pxd, settings);
         var newRoot = (XElement)CleanupTransform(pxd.Root);
         pxd.Root.ReplaceWith(newRoot);
         part.PutXDocument();
     }
 }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:49,代码来源:FormattingAssembler.cs

示例8: NormalizeListItems

 private static void NormalizeListItems(FormattingAssemblerInfo fai, WordprocessingDocument wDoc, FormattingAssemblerSettings settings)
 {
     foreach (var part in wDoc.ContentParts())
     {
         var pxd = part.GetXDocument();
         XElement newRoot = (XElement)NormalizeListItemsTransform(fai, wDoc, pxd.Root, settings);
         if (newRoot.Attribute(XNamespace.Xmlns + "pt14") == null)
             newRoot.Add(new XAttribute(XNamespace.Xmlns + "pt14", PtOpenXml.pt.NamespaceName));
         if (newRoot.Attribute(XNamespace.Xmlns + "mc") == null)
             newRoot.Add(new XAttribute(XNamespace.Xmlns + "mc", MC.mc.NamespaceName));
         pxd.Root.ReplaceWith(newRoot);
     }
 }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:13,代码来源:FormattingAssembler.cs

示例9: FontAndCharSetAnalysis

        private static void FontAndCharSetAnalysis(WordprocessingDocument wDoc, List<XElement> metrics, List<string> notes)
        {
            FormattingAssemblerSettings settings = new FormattingAssemblerSettings
            {
                RemoveStyleNamesFromParagraphAndRunProperties = false,
                ClearStyles = true,
                RestrictToSupportedNumberingFormats = false,
                RestrictToSupportedLanguages = false,
            };
            FormattingAssembler.AssembleFormatting(wDoc, settings);
            var formattingMetrics = new FormattingMetrics();

            foreach (var part in wDoc.ContentParts())
            {
                var xDoc = part.GetXDocument();
                foreach (var run in xDoc.Descendants(W.r))
                {
                    formattingMetrics.RunCount++;
                    AnalyzeRun(run, metrics, notes, formattingMetrics, part.Uri.ToString());
                }
            }

            metrics.Add(new XElement(H.RunCount, new XAttribute(H.Val, formattingMetrics.RunCount)));
            if (formattingMetrics.RunWithoutRprCount > 0)
                metrics.Add(new XElement(H.RunWithoutRprCount, new XAttribute(H.Val, formattingMetrics.RunWithoutRprCount)));
            if (formattingMetrics.ZeroLengthText > 0)
                metrics.Add(new XElement(H.ZeroLengthText, new XAttribute(H.Val, formattingMetrics.ZeroLengthText)));
            if (formattingMetrics.MultiFontRun > 0)
                metrics.Add(new XElement(H.MultiFontRun, new XAttribute(H.Val, formattingMetrics.MultiFontRun)));
            if (formattingMetrics.AsciiCharCount > 0)
                metrics.Add(new XElement(H.AsciiCharCount, new XAttribute(H.Val, formattingMetrics.AsciiCharCount)));
            if (formattingMetrics.CSCharCount > 0)
                metrics.Add(new XElement(H.CSCharCount, new XAttribute(H.Val, formattingMetrics.CSCharCount)));
            if (formattingMetrics.EastAsiaCharCount > 0)
                metrics.Add(new XElement(H.EastAsiaCharCount, new XAttribute(H.Val, formattingMetrics.EastAsiaCharCount)));
            if (formattingMetrics.HAnsiCharCount > 0)
                metrics.Add(new XElement(H.HAnsiCharCount, new XAttribute(H.Val, formattingMetrics.HAnsiCharCount)));
            if (formattingMetrics.AsciiRunCount > 0)
                metrics.Add(new XElement(H.AsciiRunCount, new XAttribute(H.Val, formattingMetrics.AsciiRunCount)));
            if (formattingMetrics.CSRunCount > 0)
                metrics.Add(new XElement(H.CSRunCount, new XAttribute(H.Val, formattingMetrics.CSRunCount)));
            if (formattingMetrics.EastAsiaRunCount > 0)
                metrics.Add(new XElement(H.EastAsiaRunCount, new XAttribute(H.Val, formattingMetrics.EastAsiaRunCount)));
            if (formattingMetrics.HAnsiRunCount > 0)
                metrics.Add(new XElement(H.HAnsiRunCount, new XAttribute(H.Val, formattingMetrics.HAnsiRunCount)));

            if (formattingMetrics.Languages.Any())
            {
                var uls = formattingMetrics.Languages.StringConcatenate(s => s + ",").TrimEnd(',');
                metrics.Add(new XElement(H.Languages, new XAttribute(H.Val, PtUtils.MakeValidXml(uls))));
            }
        }
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:52,代码来源:MetricsGetter.cs

示例10: NumberingFormatListAssembly

 private static void NumberingFormatListAssembly(WordprocessingDocument wDoc, List<XElement> metrics)
 {
     List<string> numFmtList = new List<string>();
     foreach (var part in wDoc.ContentParts())
     {
         var xDoc = part.GetXDocument();
         numFmtList = numFmtList.Concat(xDoc
             .Descendants(W.p)
             .Select(p =>
             {
                 ListItemRetriever.RetrieveListItem(wDoc, p, null);
                 ListItemRetriever.ListItemInfo lif = p.Annotation<ListItemRetriever.ListItemInfo>();
                 if (lif != null && lif.IsListItem && lif.Lvl(ListItemRetriever.GetParagraphLevel(p)) != null)
                 {
                     string numFmtForLevel = (string)lif.Lvl(ListItemRetriever.GetParagraphLevel(p)).Elements(W.numFmt).Attributes(W.val).FirstOrDefault();
                     if (numFmtForLevel == null)
                     {
                         var numFmtElement = lif.Lvl(ListItemRetriever.GetParagraphLevel(p)).Elements(MC.AlternateContent).Elements(MC.Choice).Elements(W.numFmt).FirstOrDefault();
                         if (numFmtElement != null && (string)numFmtElement.Attribute(W.val) == "custom")
                             numFmtForLevel = (string)numFmtElement.Attribute(W.format);
                     }
                     return numFmtForLevel;
                 }
                 return null;
             })
             .Where(s => s != null)
             .Distinct())
             .ToList();
     }
     if (numFmtList.Any())
     {
         var nfls = numFmtList.StringConcatenate(s => s + ",").TrimEnd(',');
         metrics.Add(new XElement(H.NumberingFormatList, new XAttribute(H.Val, PtUtils.MakeValidXml(nfls))));
     }
 }
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:35,代码来源:MetricsGetter.cs

示例11: ValidateWordprocessingDocument

        private static bool ValidateWordprocessingDocument(WordprocessingDocument wDoc, List<XElement> metrics, List<string> notes, Dictionary<XName, int> metricCountDictionary)
        {
            bool valid = ValidateAgainstSpecificVersion(wDoc, metrics, DocumentFormat.OpenXml.FileFormatVersions.Office2007, H.SdkValidationError2007);
            valid |= ValidateAgainstSpecificVersion(wDoc, metrics, DocumentFormat.OpenXml.FileFormatVersions.Office2010, H.SdkValidationError2010);
#if !NET35
            valid |= ValidateAgainstSpecificVersion(wDoc, metrics, DocumentFormat.OpenXml.FileFormatVersions.Office2013, H.SdkValidationError2013);
#endif

            int elementCount = 0;
            int paragraphCount = 0;
            int textCount = 0;
            foreach (var part in wDoc.ContentParts())
            {
                XDocument xDoc = part.GetXDocument();
                foreach (var e in xDoc.Descendants())
                {
                    if (e.Name == W.txbxContent)
                        IncrementMetric(metricCountDictionary, H.TextBox);
                    else if (e.Name == W.sdt)
                        IncrementMetric(metricCountDictionary, H.ContentControl);
                    else if (e.Name == W.customXml)
                        IncrementMetric(metricCountDictionary, H.CustomXmlMarkup);
                    else if (e.Name == W.fldChar)
                        IncrementMetric(metricCountDictionary, H.ComplexField);
                    else if (e.Name == W.fldSimple)
                        IncrementMetric(metricCountDictionary, H.SimpleField);
                    else if (e.Name == W.altChunk)
                        IncrementMetric(metricCountDictionary, H.AltChunk);
                    else if (e.Name == W.tbl)
                        IncrementMetric(metricCountDictionary, H.Table);
                    else if (e.Name == W.hyperlink)
                        IncrementMetric(metricCountDictionary, H.Hyperlink);
                    else if (e.Name == W.framePr)
                        IncrementMetric(metricCountDictionary, H.LegacyFrame);
                    else if (e.Name == W.control)
                        IncrementMetric(metricCountDictionary, H.ActiveX);
                    else if (e.Name == W.subDoc)
                        IncrementMetric(metricCountDictionary, H.SubDocument);
                    else if (e.Name == VML.imagedata || e.Name == VML.fill || e.Name == VML.stroke || e.Name == A.blip)
                    {
                        var relId = (string)e.Attribute(R.embed);
                        if (relId != null)
                            ValidateImageExists(part, relId, metricCountDictionary);
                        relId = (string)e.Attribute(R.pict);
                        if (relId != null)
                            ValidateImageExists(part, relId, metricCountDictionary);
                        relId = (string)e.Attribute(R.id);
                        if (relId != null)
                            ValidateImageExists(part, relId, metricCountDictionary);
                    }

                    if (part.Uri == wDoc.MainDocumentPart.Uri)
                    {
                        elementCount++;
                        if (e.Name == W.p)
                            paragraphCount++;
                        if (e.Name == W.t)
                            textCount += ((string)e).Length;
                    }
                }
            }

            foreach (var item in metricCountDictionary)
            {
                metrics.Add(
                    new XElement(item.Key, new XAttribute(H.Val, item.Value)));
            }

            metrics.Add(new XElement(H.ElementCount, new XAttribute(H.Val, elementCount)));
            metrics.Add(new XElement(H.AverageParagraphLength, new XAttribute(H.Val, (int)((double)textCount / (double)paragraphCount))));

            if (RevisionAccepter.HasTrackedRevisions(wDoc))
                metrics.Add(new XElement(H.RevisionTracking, new XAttribute(H.Val, true)));

            if (wDoc.GetAllParts().Any(part => part.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
                metrics.Add(new XElement(H.EmbeddedXlsx, new XAttribute(H.Val, true)));

            NumberingFormatListAssembly(wDoc, metrics);

            XDocument wxDoc = wDoc.MainDocumentPart.GetXDocument();

            foreach (var d in wxDoc.Descendants())
            {
                if (d.Name == W.saveThroughXslt)
                {
                    string rid = (string)d.Attribute(R.id);
                    var tempExternalRelationship = wDoc
                        .MainDocumentPart
                        .DocumentSettingsPart
                        .ExternalRelationships
                        .FirstOrDefault(h => h.Id == rid);
                    if (tempExternalRelationship == null)
                        metrics.Add(new XElement(H.InvalidSaveThroughXslt, new XAttribute(H.Val, true)));
                    valid = false;
                }
                else if (d.Name == W.trackRevisions)
                    metrics.Add(new XElement(H.TrackRevisionsEnabled, new XAttribute(H.Val, true)));
                else if (d.Name == W.documentProtection)
                    metrics.Add(new XElement(H.DocumentProtection, new XAttribute(H.Val, true)));
            }
//.........这里部分代码省略.........
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:101,代码来源:MetricsGetter.cs

示例12: InitializeListItemRetriever

        private static void InitializeListItemRetriever(WordprocessingDocument wordDoc, ListItemRetrieverSettings settings)
        {
            foreach (var part in wordDoc.ContentParts())
                InitializeListItemRetrieverForPart(wordDoc, part, settings);

#if false
            foreach (var part in wordDoc.ContentParts())
	        {
                var xDoc = part.GetXDocument();
                var paras = xDoc
                    .Descendants(W.p)
                    .Where(p =>
                        p.Annotation<ListItemInfo>() == null);
                if (paras.Any())
                    Console.WriteLine("Error");
	        }
#endif
        }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:18,代码来源:ListItemRetriever.cs


注:本文中的WordprocessingDocument.ContentParts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。