This is a migrated thread and some comments may be shown as answers.

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

6 Answers 166 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Jan 2011, 02:03 AM

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?

6 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 31 Jan 2011, 01:16 PM
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>>
0
David
Top achievements
Rank 1
answered on 04 Feb 2011, 12:01 PM
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.

0
Iva Toteva
Telerik team
answered on 07 Feb 2011, 10:47 AM
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>>
0
David
Top achievements
Rank 1
answered on 08 Feb 2011, 02:01 AM
Excellent! It works, Thanks so much!
0
ankur anand
Top achievements
Rank 1
answered on 16 Dec 2011, 04:34 AM
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
0
Boby
Telerik team
answered on 20 Dec 2011, 01:59 PM
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 >>

Tags
RichTextBox
Asked by
David
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
David
Top achievements
Rank 1
ankur anand
Top achievements
Rank 1
Boby
Telerik team
Share this question
or