OpenXmlRegex.Replace

Home Forums Tools OpenXmlRegex.Replace

This topic contains 1 reply, has 1 voice, and was last updated by  rabeeh 12 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #11347

    rabeeh
    Participant

    It worked placeholderValue = placeholderValue.ReplaceLineEndings();

    public void WordReplacePlaceHolders(string sourceFilePath, Dictionary<string, string> placeholders, string outputFilePath)
    {
    File.Copy(sourceFilePath, outputFilePath, true);

    using (var doc = WordprocessingDocument.Open(outputFilePath, true))
    {
    foreach (var part in doc.ContentParts())
    {
    var xdoc = part.GetXDocument();
    var content = xdoc.Descendants(W.p);

    foreach (string placeholder in placeholders.Keys)
    {
    var regex = new Regex(placeholder, RegexOptions.IgnoreCase);

    var placeholderValue = placeholders[placeholder];

    placeholderValue = placeholderValue.ReplaceLineEndings();

    OpenXmlRegex.Replace(content, regex, placeholderValue, null);
    }

    part.PutXDocument();
    }

    doc.Save();
    }

    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.