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


C# Paragraph.InsertAfterSelf方法代码示例

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


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

示例1: generaPreventivo

        public void generaPreventivo(Preventivo prev, List<PreventivoRiga> righe)
        {
            _preventivo = prev;
            _preventivoRighe = righe;
            //declare and open a Word document object
            WordprocessingDocument objWordDocx;

            System.IO.File.Copy(_TemplatePath, _DestinationPath, true);

            objWordDocx = WordprocessingDocument.Open(_DestinationPath, true);
            _MainPart = objWordDocx.MainDocumentPart;
            //get the main document section of the document
            OpenXmlElement objMainDoc;
            objMainDoc = _MainPart.Document;

            #region fieldMerge
            //fill a dummy dictionary of values to fill the template
            Dictionary<string, string> values = new Dictionary<string, string>();
            values["RagioneSociale"] = _preventivo.RagioneSociale;
            values["Indirizzo01"] = _preventivo.Indirizzo01;
            values["Indirizzo02"] = _preventivo.Indirizzo02;
            values["Oggetto"] = _preventivo.Oggetto;
            values["ModalitaPagamento"] = _preventivo.ModalitaPagamento;
            values["TrasportoMontaggio"] = _preventivo.TrasportoMontaggio;
            values["validitaOfferta"] = _preventivo.ValiditaOfferta;
            values["UtenteReferente"] = _preventivo.UtenteReferente;
            values["TelefonoReferente"] = _preventivo.TelefonoReferente;
            values["DataPreventivo"] = _preventivo.DataPreventivo;


            //Loop through merge fields
            foreach (var objField in objMainDoc.Descendants<SimpleField>())
            {
                //Clean the field name
                string strFieldName = GetFieldName(objField);

                if (!string.IsNullOrEmpty(strFieldName))
                {
                    //check if we have a value for this merge field
                    if (values.ContainsKey(strFieldName) && !string.IsNullOrEmpty(values[strFieldName]))
                    {
                        //Find the XML placeholder
                        string strRunProp = null;
                        if (objField != null)
                        {
                            foreach (RunProperties objRP in objField.Descendants<RunProperties>())
                            {
                                strRunProp = objRP.OuterXml;
                                break;  // break at first
                            }
                        }

                        Run objRun = new Run();
                        if (!string.IsNullOrEmpty(strRunProp))
                        {
                            objRun.Append(new RunProperties(strRunProp));
                        }
                        //add the text to the place holder
                        objRun.Append(new Text(values[strFieldName]));

                        //replace the merge field with the value
                        objField.Parent.ReplaceChild<SimpleField>(objRun, objField);

                    }
                }

            }
            #endregion

            #region Create Table
            var res = from bm in objWordDocx.MainDocumentPart.Document.Body.Descendants<BookmarkStart>()
                      where bm.Name == "CORPO"
                      select bm;
            var bookmark = res.SingleOrDefault();
            if (bookmark != null)
            {
                var parent = bookmark.Parent;   // bookmark's parent element

                // simple paragraph in one declaration
                //Paragraph newParagraph = new Paragraph(new Run(new Text("Hello, World!")));

                // build paragraph piece by piece
                //Text text = new Text("Contenuto");
                Run run = new Run(new RunProperties(new Bold()));
                //run.Append(text);
                Paragraph newParagraph = new Paragraph(run);

                // insert after bookmark parent
                parent.InsertAfterSelf(newParagraph);

                // insert after new paragraph
                newParagraph.InsertAfterSelf(GenerateTable());
            }
            #endregion

            //save this part
            objWordDocx.MainDocumentPart.Document.Save();
            //save and close the document
            objWordDocx.Close();

//.........这里部分代码省略.........
开发者ID:PaoloMisson,项目名称:GATEvolution,代码行数:101,代码来源:GenerateCodeXML.cs


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