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


C# Paragraph.Elements方法代码示例

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


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

示例1: ApplyStyleToParagraph

        // Apply a style to a paragraph.
        public static void ApplyStyleToParagraph(StyleDefinitionsPart part,
            string styleId, Paragraph p)
        {
            // If the paragraph has no ParagraphProperties object, create one.
            if (p.Elements<ParagraphProperties>().Count() == 0)
            {
                p.PrependChild<ParagraphProperties>(new ParagraphProperties());
            }

            // Get the paragraph properties element of the paragraph.
            ParagraphProperties pPr = p.Elements<ParagraphProperties>().First();

            // Set the style of the paragraph.
            pPr.ParagraphStyleId = new ParagraphStyleId() { Val = styleId };
        }
开发者ID:cometofsky,项目名称:Quran,代码行数:16,代码来源:GenerateWord.ashx.cs

示例2: CreateParagraphPropertiesIfNonExists

 internal static void CreateParagraphPropertiesIfNonExists(Paragraph paragraph)
 {
     // If the paragraph has no ParagraphProperties object, create one.
     if (paragraph.Elements<ParagraphProperties>().Count() == 0) {
         paragraph.PrependChild<ParagraphProperties>(new ParagraphProperties());
     }
 }
开发者ID:FerHenrique,项目名称:Owl,代码行数:7,代码来源:WordHelper.cs

示例3: ParagraphIndexer

        public ParagraphIndexer(Paragraph toIndex)
        {
            if (toIndex == null)
            {
                throw new ArgumentNullException("paragraph");
            }

            this.Paragraph = toIndex;
            this.Properties = toIndex.Elements<ParagraphProperties>().FirstOrDefault();

            // Process runs.
            foreach (var run in toIndex.Elements<Run>())
            {
                this.runs.Add(new RunIndexer(run));
            }
        }
开发者ID:jduv,项目名称:IndexML,代码行数:16,代码来源:ParagraphIndexer.cs

示例4: ApplyStyleToParagraph

        // Apply a style to a paragraph.
        public void ApplyStyleToParagraph(WordprocessingDocument doc, string styleid, string stylename, Paragraph p)
        {
            // If the paragraph has no ParagraphProperties object, create one.
            if (p.Elements<ParagraphProperties>().Count() == 0)
            {
                p.PrependChild(new ParagraphProperties());
            }

            // Get the paragraph properties element of the paragraph.
            ParagraphProperties pPr = p.Elements<ParagraphProperties>().First();

            // Get the Styles part for this document.
            StyleDefinitionsPart part =
                doc.MainDocumentPart.StyleDefinitionsPart;

            // If the Styles part does not exist, add it and then add the style.
            if (part == null)
            {
                part = this.AddStylesPartToPackage(doc);
                AddNewStyle(part, styleid, stylename);
            }
            else
            {
                // If the style is not in the document, add it.
                if (this.IsStyleIdInDocument(doc, styleid) != true)
                {
                    // No match on styleid, so let's try style name.
                    string styleidFromName = this.GetStyleIdFromStyleName(doc, stylename);
                    if (styleidFromName == null)
                    {
                        AddNewStyle(part, styleid, stylename);
                    }
                    else
                    {
                        styleid = styleidFromName;
                    }
                }
            }

            // Set the style of the paragraph.
            pPr.ParagraphStyleId = new ParagraphStyleId { Val = styleid };
        }
开发者ID:MikeThomas64,项目名称:pickles,代码行数:43,代码来源:WordStyleApplicator.cs

示例5: Main

        static void Main(string[] args)
        {
            string FilePath = @"..\..\..\..\Sample Files\";
            string File = FilePath + "Create and add a paragraph style - OpenXML.docx";

            using (WordprocessingDocument doc =
                WordprocessingDocument.Open(File, true))
            {
                // Get the Styles part for this document.
                StyleDefinitionsPart part =
                    doc.MainDocumentPart.StyleDefinitionsPart;

                // If the Styles part does not exist, add it and then add the style.
                if (part == null)
                {
                    part = AddStylesPartToPackage(doc);
                }

                // Set up a variable to hold the style ID.
                string parastyleid = "OverdueAmountPara";

                // Create and add a paragraph style to the specified styles part 
                // with the specified style ID, style name and aliases.
                CreateAndAddParagraphStyle(part,
                    parastyleid,
                    "Overdue Amount Para",
                    "Late Due, Late Amount");

                // Add a paragraph with a run and some text.
                Paragraph p =
                    new Paragraph(
                        new Run(
                            new Text("This is some text in a run in a paragraph.")));

                // Add the paragraph as a child element of the w:body element.
                doc.MainDocumentPart.Document.Body.AppendChild(p);

                // If the paragraph has no ParagraphProperties object, create one.
                if (p.Elements<ParagraphProperties>().Count() == 0)
                {
                    p.PrependChild<ParagraphProperties>(new ParagraphProperties());
                }

                // Get a reference to the ParagraphProperties object.
                ParagraphProperties pPr = p.ParagraphProperties;

                // If a ParagraphStyleId object doesn't exist, create one.
                if (pPr.ParagraphStyleId == null)
                    pPr.ParagraphStyleId = new ParagraphStyleId();

                // Set the style of the paragraph.
                pPr.ParagraphStyleId.Val = parastyleid;
            }
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:54,代码来源:Program.cs

示例6: Test_03

        public static void Test_03()
        {
            //Test_OpenXml_Style.SetDirectory();
            string file = "test_01.docx";
            Trace.WriteLine("create docx \"{0}\" using OXmlDoc", file);

            // from How to: Create and add a paragraph style to a word processing document (Open XML SDK) https://msdn.microsoft.com/fr-fr/library/office/gg188062.aspx

            using (WordprocessingDocument doc = WordprocessingDocument.Open(file, true))
            {
                // Get the Styles part for this document.
                StyleDefinitionsPart part = doc.MainDocumentPart.StyleDefinitionsPart;

                // If the Styles part does not exist, add it and then add the style.
                if (part == null)
                {
                    part = AddStylesPartToPackage(doc);
                }

                // Set up a variable to hold the style ID.
                string parastyleid = "OverdueAmountPara";

                // Create and add a paragraph style to the specified styles part 
                // with the specified style ID, style name and aliases.
                CreateAndAddParagraphStyle(part, parastyleid, "Overdue Amount Para", "Late Due, Late Amount");

                // Add a paragraph with a run and some text.
                //Paragraph p = new Paragraph(new Run(new Text("This is some text in a run in a paragraph.")));
                Paragraph p = new Paragraph(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text("This is some text in a run in a paragraph.")));

                // Add the paragraph as a child element of the w:body element.
                doc.MainDocumentPart.Document.Body.AppendChild(p);

                // If the paragraph has no ParagraphProperties object, create one.
                if (p.Elements<ParagraphProperties>().Count() == 0)
                {
                    p.PrependChild<ParagraphProperties>(new ParagraphProperties());
                }

                // Get a reference to the ParagraphProperties object.
                ParagraphProperties pPr = p.ParagraphProperties;

                // If a ParagraphStyleId object doesn't exist, create one.
                if (pPr.ParagraphStyleId == null)
                    pPr.ParagraphStyleId = new ParagraphStyleId();

                // Set the style of the paragraph.
                pPr.ParagraphStyleId.Val = parastyleid;
            }
        }
开发者ID:labeuze,项目名称:source,代码行数:50,代码来源:Test_OpenXml_Style_v1.cs

示例7: setStyle

        //public static StyleDefinitionsPart getStyles(string path)
        //{
        //    try
        //    {
        //        StyleDefinitionsPart part = new StyleDefinitionsPart();

        //        using (WordprocessingDocument wordTemplate = WordprocessingDocument.Open(path, true))
        //        {
        //            foreach (var templateStyle in wordTemplate.MainDocumentPart.StyleDefinitionsPart.Styles)
        //            {
        //                part.Styles.Append(templateStyle.CloneNode(true));
        //            }
        //        }

        //        return part;
        //    }
        //    catch (Exception)
        //    {
                
        //        return null;
        //    }
        //}

        // Set new Style for paragraph.
        public static void setStyle(WordprocessingDocument doc, Paragraph p, StyleRunProperties prop, string id, string stylename, string alias)
        {
            // Get the Styles part for this document. If it does not exist create one
            StyleDefinitionsPart part = doc.MainDocumentPart.StyleDefinitionsPart;
            if (part == null) { part = AddStylesPartToPackage(doc); }

            CreateAndAddParagraphStyle(prop, part, id, stylename, alias);

            // If the paragraph has no ParagraphProperties object, create one.
            if (p.Elements<ParagraphProperties>().Count() == 0)
            {
                p.PrependChild<ParagraphProperties>(new ParagraphProperties());
            }

            // Get a reference to the ParagraphProperties object.
            ParagraphProperties pPr = p.ParagraphProperties;

            // If a ParagraphStyleId object doesn't exist, create one.
            if (pPr.ParagraphStyleId == null)
                pPr.ParagraphStyleId = new ParagraphStyleId();

            // Set the style of the paragraph.
            pPr.ParagraphStyleId.Val = id;
        }
开发者ID:JorgeFlorido,项目名称:CSharp,代码行数:48,代码来源:Word.cs

示例8: AddParagraph

        /// <summary>
        /// Add paragraph
        /// </summary>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        private string AddParagraph(Paragraph paragraph)
        {
            try
            {
                string paragraphTemplate = "<p class=STYLE>PARAGRAPH_CONTENT</p>";
                string paragraphStyle = paragraph.ParagraphProperties != null ? AddFormatParagraph(paragraph.ParagraphProperties) : "\"\"";

                string paragraphContent = "";

                foreach (OpenXmlElement element in paragraph.Elements())
                    if (element is Run)
                        paragraphContent += AddRun((Run)element);
                    else if (element is Hyperlink)
                        paragraphContent += AddHyperlink((Hyperlink)element);

                return paragraphTemplate.Replace("STYLE", paragraphStyle)
                    .Replace("PARAGRAPH_CONTENT", paragraphContent == "" ? "&nbsp;" : paragraphContent) + Environment.NewLine;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:28,代码来源:DocxToHtml.cs


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