rabeeh

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: OpenXmlRegex.Replace #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)