Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Editor > Formatted text copied from Word
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Formatted text copied from Word

Feed from this thread
  • Posted on Aug 28, 2007 (permalink)

    Hello,

    We have some issue with formatted text copied from Word.
    If I copy centered text from Word, for example the following: 

    Test

    Test3

    Hgdfhg5

    then I cannot to change alignment of the text.
    I got the message that Word format will be cleared when I pasted the text.

    How may I solve the issue?

    Regards,
    Olga

  • Rumen Rumen admin's avatar

    Posted on Aug 28, 2007 (permalink)

    Hi Olga,

    RadEditor just strips the MS Word formatting tags and attributes when pasting from Word in its content area. If you paste your content and does not strip the Word formatting you will see how the original content look. Here it is

    <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center>Test</p>
    <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center>Test3</p>
    <p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center>Hgdfhg5</p>

    You can see that there is a style TEXT-ALIGN: center as well as align="center" attribute.
    So when you apply left alignment to the first link from the toolbar button you will see that the command is applied only to the align attribute, but not to the TEXT-ALIGN attribute - which is the reason for the problem, e.g.

    <P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=left>Test</P>

    To fix the problem you should strip the style attribute information from the pasted content. To do that you should set the StripFormattingOnPaste to "MSWord,Css"

    <radE:RadEditor id="RadEditor1" StripFormattingOnPaste="MSWord,Css" Runat="server"></radE:RadEditor>

    Thus when you paste MS Word content the editor will automatically strip the MSWord formatting and style attributes.
    Here how the produced content will look

    <P align=center>Test</P>
    <P align=right>Test3</P>
    <P align=center>Hgdfhg5</P>

    which will allow you to align the three lines in the content area.

    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Paul avatar

    Posted on Sep 7, 2007 (permalink)

    Is there an automated way to strip both MSWordNoFontsNoSizes and CSS in the Mozilla (Firefox) browsers?

  • Rumen Rumen admin's avatar

    Posted on Sep 8, 2007 (permalink)

    Hi Paul,

    You can use the following JavaScript function to strip MS Word content formatting on editor load by attaching it to the editor OnClientLoad event, e.g.

    <script type="text/javascript">
    function OnClientLoad(editor)
    {
       // the code below will call the Format Stripper tool with the "Word" option
       // the other possible options are All, CSS, WORD_ALL

       oTool = new Object();
       oTool.GetSelectedValue = function() { return "WORD"; }
       editor.Fire("FormatStripper", oTool);
    }
    </script>

    <rade:RadEditor id="RadEditor1" Runat="server" SaveInFile=true OnClientLoad="OnClientLoad">

    <p><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">  </p>
    <p class=MsoNormal><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; BACKGROUND: red; COLOR: #ff9900; mso-bidi-font-family: Arial; mso-highlight: red">Sampe MS Word content</span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: #ff9900; mso-bidi-font-family: Arial"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></b></p></span></span>

    </rade:RadEditor>

    You can also fire the stripping code below when submitting the content too by using the OnClientSubmit event

          <script type="text/javascript">
    function OnClientSubmit(editor)
    {
       // the code below will call the Format Stripper tool with the "Word" option
       // the other possible options are All, CSS, WORD_ALL
       oTool = new Object();
       oTool.GetSelectedValue = function() { return "WORD"; }
       editor.Fire("FormatStripper", oTool);
    }
    </script>

    <rade:RadEditor OnClientSubmit="OnClientSubmit" id="RadEditor1" Editable="true" Runat="server" SaveInFile=true>

    <p><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">  </p>
    <p class=MsoNormal><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; BACKGROUND: red; COLOR: #ff9900; mso-bidi-font-family: Arial; mso-highlight: red">Sampe MS Word content</span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: #ff9900; mso-bidi-font-family: Arial"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></b></p></span></span>

    </rade:RadEditor>

    The code works for IE and Mozilla (Firefox).

    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • David Tsao avatar

    Posted on May 19, 2008 (permalink)

    I want to be able to automatically strip Word formatting from text pasted into the RadEditor when using FireFox. Given that the StripFormattingOnPaste option does not work with Firefox, I tried using OnClientSubmit to fire the FormatStripper tool (per Rumen's post) when the editor submits its data to the server. The problem I'm having is that I can only get the OnClientSubmit event to fire if the editor's built in Update button is clicked, but not when my page's submit button is clicked.

    My pages use multiple RadEditors plus other input controls (text boxes, radio buttons, etc.). I have a single submit button and have turned off the built in submit/cancel buttons in the RadEditors.

    Is there another way to strip out Word formatting in my scenario? Stripping the formatting via server side code is another possibility. I'm wondering is anyone has server side code to do the equivalent of:

    .StripFormattingOnPaste = Telerik.WebControls.EditorStripFormattingOptions.MSWordRemoveAll Or _  
       Telerik.WebControls.EditorStripFormattingOptions.Css  
     

    Thanks

  • Rumen Rumen admin's avatar

    Posted on May 20, 2008 (permalink)

    Hello David,

    Please, use the RADEVENT_SUBMIT event of RadEditor, which will be fired when the page postbacks:

    <script type="text/javascript">
    function OnClientLoad(editor)
    {
       editor.AttachEventHandler ("RADEVENT_SUBMIT", function (e)
       {
       // the code below will call the Format Stripper tool with the "Word" option
       // the other possible options are All, CSS, WORD_ALL
       oTool = new Object();
       oTool.GetSelectedValue = function() { return "WORD"; }
       editor.Fire("FormatStripper", oTool);
       });
    }
    </script>

    <rade:RadEditor OnClientLoad="OnClientLoad" id="RadEditor1" Runat="server" SaveInFile=true>

    <p><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">  </p>
    <p class=MsoNormal><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; BACKGROUND: red; COLOR: #ff9900; mso-bidi-font-family: Arial; mso-highlight: red">Sampe MS Word content</span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: #ff9900; mso-bidi-font-family: Arial"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></span></b></p></span></span>

    </rade:RadEditor>
    <asp:Button ID="Button1" runat="server" Text="Button" />

    Sincerely yours,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • David Tsao avatar

    Posted on May 20, 2008 (permalink)

    Rumen,

    Attaching to the RADEVENT_SUBMIT makes my app work correctly. Thanks so much.

    David

  • Chris Cottrell avatar

    Posted on Feb 24, 2011 (permalink)

    This seems to be a fairly old thread so I am not sure if anyone is monitoring this, but what I need to do is fire the ConvertWordLists formatting option. I know this is a fairly new option, but I can't find any documentation that states how we should do this. 

    Here is my script, which is working well to remove all word formatting. It does look a little different from your examples here.

    <script type="text/javascript">
          function radEditor_OnClientSubmit(editor) {
               editor.fire("FormatStripper", { value: "WORD_ALL" });
          }
    </script>

    I just need to know what that keyword I should be using is. Since it doesn't seem as straightforward as it should be. MSWordRemoveAll is the option I have set for the stripFormattingOptions and StripFormattingOnPaste so who would have thought I should be using "WORD_ALL"?  I want it to format my lists as UL, LI format.

    Thanks!

  • Rumen Rumen admin's avatar

    Posted on Feb 25, 2011 (permalink)

    Hello Chris,

    The requested feature is not available for the FormatStripper command and I logged your requirement as a future request that we will implement in one of the upcoming versions of RadEditor. Here you can find the PITS Issue: Public URL.

    Currently, you can achieve your scenario using the following code:
    Copy Code
    <telerik:RadEditor ID="RadEditor1" OnClientSubmit="OnClientSubmit" runat="server">
    </telerik:RadEditor>
    <script type="text/javascript">
        function OnClientSubmit(editor) {
            editor.set_html(Telerik.Web.UI.Editor.Utils.convertWordLists(editor.get_html()));
            editor.fire("FormatStripper", { value: "WORD_ALL" });
     
            alert(editor.get_html(true));
        }
    </script>



    All the best,
    Rumen
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

  • Ted avatar

    Posted on Jun 9, 2011 (permalink)

    is there a place to find the latest FormatStripper options?

    I'm trying to create a custom button that will format the text the way we want it using this.
    Telerik.Web.UI.Editor.CommandList["CustomFormatStripper"] = function (commandName, editor, args) {
                //"MSWordRemoveAll,Span,Css,ConvertWordLists,Font"
                editor.fire("FormatStripper", { value: "WORD_ALL" });
                editor.fire("FormatStripper", { value: "CSS" });
                editor.fire("FormatStripper", { value: "FONT" });
                editor.set_html(Telerik.Web.UI.Editor.Utils.convertWordLists(editor.get_html()));
      
                var contentBlock = editor.get_html(true);
      
                contentBlock = contentBlock.replace(/\r\n/g, "");
                contentBlock = contentBlock.replace(/\n/g, "");
                contentBlock = contentBlock.replace(/\r/g, "");
      
                editor.set_html(contentBlock);  
      
            };

  • Rumen Rumen admin's avatar

    Posted on Jun 13, 2011 (permalink)

    Hi Ted,

    The available options of the FormatStripper command are ALL, ALL_NO_BRAKES, CSS, SPAN, FONT, WORD, WORD_ALL and WORD_NO_FONTS.

    All the best,
    Rumen
    the Telerik team

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

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Editor > Formatted text copied from Word