internal static Run GetRunElementForPicture(Picture picture, SimpleField placeHolder) { string outerXml = (string)null; if (placeHolder != null) { using (IEnumerator <RunProperties> enumerator = placeHolder.Descendants <RunProperties>().GetEnumerator()) { if (enumerator.MoveNext()) { outerXml = enumerator.Current.OuterXml; } } } Run run = new Run(); if (!string.IsNullOrEmpty(outerXml)) { run.Append(new OpenXmlElement[1] { (OpenXmlElement) new RunProperties(outerXml) }); } if (picture == null) { ; } return(run); }
/// <summary> /// Returns a <see cref="Run"/>-openxml element for the given text. /// Specific about this run-element is that it can describe multiple-line and tabbed-text. /// The <see cref="SimpleField"/> placeholder can be provided too, to allow duplicating the formatting. /// </summary> /// <param name="text">The text to be inserted.</param> /// <param name="placeHolder">The placeholder where the text will be inserted.</param> /// <returns>A new <see cref="Run"/>-openxml element containing the specified text.</returns> private Run GetRunElementForText(string text, SimpleField placeHolder) { string rpr = null; if (placeHolder != null) { // ReSharper disable LoopCanBeConvertedToQuery foreach (RunProperties placeholderrpr in placeHolder.Descendants <RunProperties>()) // ReSharper restore LoopCanBeConvertedToQuery { rpr = placeholderrpr.OuterXml; break; // break at first } } var r = new Run(); if (!string.IsNullOrEmpty(rpr)) { r.Append(new RunProperties(rpr)); } if (!string.IsNullOrEmpty(text)) { // first process line breaks // ReSharper disable RedundantExplicitArrayCreation string[] split = text.Split(new string[] { "\n" }, StringSplitOptions.None); // ReSharper restore RedundantExplicitArrayCreation bool first = true; foreach (string s in split) { if (!first) { r.Append(new Break()); } first = false; // then process tabs bool firsttab = true; // ReSharper disable RedundantExplicitArrayCreation string[] tabsplit = s.Split(new string[] { "\t" }, StringSplitOptions.None); // ReSharper restore RedundantExplicitArrayCreation foreach (string tabtext in tabsplit) { if (!firsttab) { r.Append(new TabChar()); } r.Append(new Text(tabtext)); firsttab = false; } } } return(r); }
private static Run GetRunElementForText(string text, SimpleField placeHolder) { string rpr = null; if (placeHolder != null) { foreach (RunProperties placeholderRpr in placeHolder.Descendants <RunProperties>()) { rpr = placeholderRpr.OuterXml; break; } } Run r = new Run(); if (!string.IsNullOrEmpty(rpr)) { r.AppendChild(new RunProperties(rpr)); } if (!string.IsNullOrEmpty(text)) { // first process line breaks string[] split = text.Split(new[] { "\n" }, StringSplitOptions.None); bool first = true; foreach (string s in split) { if (!first) { r.AppendChild(new Break()); } first = false; // then process tabs bool firstTab = true; string[] tabSplit = s.Split(new[] { "\t" }, StringSplitOptions.None); foreach (string tabText in tabSplit) { if (!firstTab) { r.AppendChild(new TabChar()); } r.AppendChild(new Text(tabText)); firstTab = false; } } } return(r); }
/// <summary> /// Returns a <see cref="Run"/>-openxml element for the given text. /// Specific about this run-element is that it can describe multiple-line and tabbed-text. /// The <see cref="SimpleField"/> placeholder can be provided too, to allow duplicating the formatting. /// </summary> /// <param name="text">The text to be inserted.</param> /// <param name="placeHolder">The placeholder where the text will be inserted.</param> /// <returns>A new <see cref="Run"/>-openxml element containing the specified text.</returns> private static Run GetRunElementForText(string text, SimpleField placeHolder) { string runProperties = null; if (placeHolder != null) { foreach (var descendant in placeHolder.Descendants <RunProperties>()) { runProperties = descendant.OuterXml; break; // break at first } } Run run = new Run(); if (!string.IsNullOrEmpty(runProperties)) { run.Append(new RunProperties(runProperties)); } if (!string.IsNullOrEmpty(text)) { // first process line breaks string[] split = text.Split(new string[] { "\n" }, StringSplitOptions.None); bool first = true; foreach (string value in split) { if (!first) { run.Append(new Break()); } first = false; // then process tabs bool firstTab = true; string[] tabSplit = value.Split(new string[] { "\t" }, StringSplitOptions.None); foreach (string tabText in tabSplit) { if (!firstTab) { run.Append(new TabChar()); } run.Append(new DocumentFormat.OpenXml.Wordprocessing.Text(tabText)); firstTab = false; } } } return(run); }
internal static Run GetRunElementForText(string text, SimpleField placeHolder) { string outerXml = (string)null; if (placeHolder != null) { using (IEnumerator <RunProperties> enumerator = placeHolder.Descendants <RunProperties>().GetEnumerator()) { if (enumerator.MoveNext()) { outerXml = enumerator.Current.OuterXml; } } } Run run = new Run(); if (!string.IsNullOrEmpty(outerXml)) { run.Append(new OpenXmlElement[1] { (OpenXmlElement) new RunProperties(outerXml) }); } if (!string.IsNullOrEmpty(text)) { string[] strArray = ((object)text).ToString().Split(new string[1] { "\n" }, StringSplitOptions.None); bool flag1 = true; foreach (string str1 in strArray) { if (!flag1) { run.Append(new OpenXmlElement[1] { (OpenXmlElement) new Break() }); } flag1 = false; bool flag2 = true; string str2 = str1; string[] separator = new string[1] { "\t" }; int num = 0; foreach (string text1 in str2.Split(separator, (StringSplitOptions)num)) { if (!flag2) { run.Append(new OpenXmlElement[1] { (OpenXmlElement) new TabChar() }); } run.Append(new OpenXmlElement[1] { (OpenXmlElement) new Text(text1) }); flag2 = false; } } } return(run); }