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

Problème when pasting from msword

3 Answers 38 Views
Editor
This is a migrated thread and some comments may be shown as answers.
ericc34
Top achievements
Rank 1
ericc34 asked on 31 Oct 2011, 04:51 PM
Here's my big problem

I paste this msword content to radeditor

Test de formulaire

Avec du rouge

Du bleu

Et du vert

User highlight Test de formulaire and click custom button with this code :

var selection = String(editor.getSelectionHtml());

                //selection = selection.replace("<q>", "");
                //selection = selection.replace("</q>", "");
                //selection = selection.replace("<Q>", "");
                //selection = selection.replace("</Q>", "");

                //Remove all custom tags before insert new custom tags
                var html = editor.get_html(false);
                html = html.replace("<q>", "");
                html = html.replace("</q>", "");
                html = html.replace("<Q>", "");
                html = html.replace("</Q>", "");

                var newhtml = html.replace(selectedText, '<q>' + selectedText + '</q>');
                //var newhtml = html.replace(selection, '<q>' + selection + '</q>');
                editor.set_html(newhtml);

                //Set schedule text
                var txtScheduleText = $find("<%=txtScheduleText.ClientID%>");
                txtScheduleText.set_mode(4);
                txtScheduleText.set_html(selection);
                txtScheduleText.set_mode(4);

This code must replace selectedhtml text like this : <FONT size=3 face=calibri>Ceci est un test</FONT>  by <q><FONT size=3 face=calibri>Ceci est un test</FONT></q>

The problem is that when i call var newhtml = html.replace(selection, '<q>' + selection + '</q>'); selection not exist in html because html look like this with msword special tag :

<FONT face=georgia>

<P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal><FONT size=3 face=calibri>Ceci est un test<?xml:namespace prefix = o /><o:p></o:p></FONT></P>

<P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal><FONT color=#ff0000 size=3 face=calibri>En rouge<o:p></o:p></FONT></P>

<P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal><FONT color=#00b0f0 size=3 face=calibri>En bleu<o:p></o:p></FONT></P>

<P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal><FONT color=#00b050 size=3 face=calibri>En vert<o:p></o:p></FONT></P></FONT>

Do you have a valid solution to replace my html selection ?

 

 

 

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 01 Nov 2011, 01:23 PM
Hello Ericc34,

You can strip the Word formatting by setting the StripFormattingOptions property to "MSWord" and once the content is cleaned to replace the desired tags.

Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
ericc34
Top achievements
Rank 1
answered on 01 Nov 2011, 01:27 PM
I'll try this and this dont't work

Can you send me a sample of it using my code ?
0
Rumen
Telerik team
answered on 01 Nov 2011, 02:22 PM
Please test the following demo: Cleaning Word Formatting.

If you are able to replicate the issue when the radio button option is enabled than the problem is most likely due to that the "Allow Programmatic Clipboard access" setting of your IE browser is disabled.
If this feature is disabled it is not possible to access the clipboard content and modify the pasted content. In such case you can enable the "Allow Programmatic Clipboard access" option or if this is not allowed to strip the content when submitting the content: Cleaning Word Formatting On Page Load And On Submit and replace the special tags on the server using the String.Replace method.


Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Editor
Asked by
ericc34
Top achievements
Rank 1
Answers by
Rumen
Telerik team
ericc34
Top achievements
Rank 1
Share this question
or