RADFlowDocument Replace Text

5 posts, 0 answers
  1. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 21 Jan 2019 Link to this post

    Hi,

    I have an existing word document and I need to remove paragraph/sentence/line.

    stream input = File.OpenRead(filepath);
    RadFlowDocument document  = provider.Import(input);

    RadFlowDocumentEditor  editor = new RadFlowDocumentEditor(document);     
    editor.ReplaceText("<Expr2>", ltr.Expr2));   
    editor.ReplaceText("<Expr3>", ltr.Expr3));

    If ltr.Expr2 is blank, then it should remove blank lines from document where <Expr2> exists, otherwise replace text with ltr.Expr2 value. 

    Any help would be greatly appreciated.

  2. Tanya
    Admin
    Tanya avatar
    878 posts

    Posted 24 Jan 2019 Link to this post

    Hi Khawar,

    The ReplaceText() method replaces only the Run elements in the document and cannot delete a paragraph. To achieve this behavior, I would suggest you to manually remove the run and, according to the value of ltr.Expr2, delete the underlying paragraph or insert the value of the variable as the Text of the Run object:
    foreach (var run in this.document.EnumerateChildrenOfType<Run>().ToList())
    {
        if (run.Text == "<Expr2>")
        {
            if (string.IsNullOrEmpty(ltr.Expr2))
            {
                var section = run.Paragraph.Parent as Section;
                section.Blocks.Remove(run.Paragraph);
            }
            else
            {
                run.Text = ltr.Expr2;
            }
        }
    }


    Regards,
    Tanya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 24 Jan 2019 in reply to Tanya Link to this post

    It worked!!Thank you so much.
  4. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 05 Dec 2019 Link to this post

    Hi Admins,

    I have a question regarding formatted text to insert in a document using RadFlowDocument editor.

    I m using  this line of code  

    editor.ReplaceText("<LetterFieldInsert>", initltr.LetterFieldInsert)

    problem is, sometimes text can have line feed (i.e. CrLf or Lf) in it and I want to show it with formatting if there is any. 

    Currently, RadFlowDocument editor isn't recognizing line feed and lumped all together or in other words, wrapped in a single sentence.

    Would you please advise, how can I fix this issue? 

    Your help is greatly appreciated.

    Thanks

     

  5. Tanya
    Admin
    Tanya avatar
    878 posts

    Posted 10 Dec 2019 Link to this post

    Hi Khawar,

    With the current implementation of the ReplaceText() method, only plain text can be inserted. The content passed as a parameter to the method is stripped from the formatting and line feeds as it needs to be added as content to a single Run element. We have a request to provide you with the ability to replace with different elements and you can vote for its implementation using the related public item: WordsProcessing: Introduce a way to replace text with other document elements. You can also follow this item if you would like to receive updates about status changes on it.

    Regards,
    Tanya
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top