示例#1
0
    public static void SetContentValue(this SdtElement Element, string Content)
    {
        var first = true;

        foreach (var run in Element.GetContent().OfType <Run>().ToArray())
        {
            if (first)
            {
                first = false;
                run.Text(Content);
            }
            else
            {
                run.Remove();
            }
        }

        //var content = Element.GetContent();
        //var run = content as Run;
        //if (run is null)
        //    run = content.Descendants<Run>().FirstOrDefault();
        //if (run is null)
        //    throw new InvalidOperationException();
        ////var run = content as Run ?? content.Descendants<Run>().First();
        //run.Text(Content);
    }
示例#2
0
    public static void ReplaceWithContentValue(this SdtElement Element, string?Content = null)
    {
        var content = Element.GetContent().ToArray();

        var first = true;

        foreach (var content_element in content)
        {
            content_element.Remove();

            if (Content == null || !first)
            {
                continue;
            }

            var run = content_element as Run ?? content_element.DescendantChilds <Run>().FirstOrDefault();
            if (run is null)
            {
                continue;
            }

            first = false;
            run.Text(Content);
            Element.InsertAfterSelf(content_element);
        }

        Element.Remove();
    }
示例#3
0
 public static void Deconstruct(this SdtElement element, out string?Tag, out string?Alias, out IEnumerable <OpenXmlElement> Content)
 {
     Tag     = element.GetTag();
     Alias   = element.GetAlias();
     Content = element.GetContent();
 }