How to Insert a table into the templates in RadRichTextBox automatically by program scripts.

7 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Jan 2011

    Posted 27 Jan 2011 Link to this post

    I would like to find out whether table can be generated automatically by program in Docx and XAML formate in RadRichTextbox ?

    For example, user put <summary table> in the template, this <summary table> should be replaced by the actual data table when user preview the report, are there anyway that this table can be generated by the program in Docx and XAML format?

  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 31 Jan 2011 Link to this post

    Hello David,

    The way I understand your use-case, it is practically mail merge - having some template and filling it with different data. This is a feature that we have planned for 2011.Q1, which is expected some time in the second half of March.
    What you can do as of now is to traverse the document, search for all occurrences of <summary table> or any other tag you will be using, and replace it with the data you wish to display. You can store the data in DOCX, XAML or HTML, but you would have to get the data entry you wish to show yourself (if you store the DOCX/ XAML/ HTML in a database), import it using the corresponding format provider and then get the table from the imported document.
    As for the import/ export from/ to DOCX and XAML, you can test how it works in our demo.
    If you need further help, do not hesitate to contact us again.

    Best wishes,
    Iva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. David
    David avatar
    4 posts
    Member since:
    Jan 2011

    Posted 04 Feb 2011 Link to this post

    Thanks, I managed to get the search and replace function done by using following code:

    private void buttonFind_Click(object sender, RoutedEventArgs e)
    {
        this.radRichTextBox.Document.Selection.Clear();
     
        DocumentTextSearch search = new DocumentTextSearch(this.radRichTextBox.Document);
        foreach (var textRange in search.FindAll(this.textBox.Text))
        {
            this.radRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition);
            this.radRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);
        }          
    }

    But the above code stops working if I want to search some strings like:  [InsertTable] or [keyword], is there any way to make it work?

    Thanks.

  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 07 Feb 2011 Link to this post

    Hi David,

    The FindAll method of the takes a string as an argument, but regards it as a regular expression. For example, searching “[a-z]*control[a-z]*” will find all words that contain the word “control” as a substring. In your case [InsertTable] looks for any of the letters I, n, s, e, r, t, etc, which probably produces a rather large output. 
    In order to find the string "[InsertTable]", you would have to escape it before proceeding with the search as follows:

    string text = Regex.Escape(this.textBox.Text);
    foreach (var textRange in search.FindAll(text))   {...}

    Let us know if you encounter any other obstacles.

    Greetings,
    Iva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  5. David
    David avatar
    4 posts
    Member since:
    Jan 2011

    Posted 07 Feb 2011 Link to this post

    Excellent! It works, Thanks so much!
  6. ankur anand
    ankur anand avatar
    2 posts
    Member since:
    Feb 2006

    Posted 15 Dec 2011 Link to this post

    Hello Iva Toteva,

    Do you have this template feature in RichTextBox now? I am looking for a similar feature where I could let the user insert a table...sort of a grid...that shows merge result in tabular format. Please let me know if it is possible in any way.


    Thanks,
    Ankur
  7. Boby
    Admin
    Boby avatar
    685 posts

    Posted 20 Dec 2011 Link to this post

    Hello Ankur Anand,
    You can benefit from our mail merge functionality - you can have a document containing table filled with merge fields and perform mail merge operation.
    If this doesn't answer your question, please share more details about your scenario, so we can adequately help you further.

    All the best,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top