本文整理汇总了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();
//.........这里部分代码省略.........