upload word document template having macros and run them in the editor

4 posts, 0 answers
  1. Ramakrishna
    Ramakrishna avatar
    10 posts
    Member since:
    Feb 2012

    Posted 12 Oct 2018 Link to this post

    Hi,

    would like to know if the Telerik editor supports uploading existing word document templates having macros in it and running those macros within the editor. if not, is there an alternate solution to achieve same or similar functionality? thanks in advance.

     

    regards,

    Rama

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5897 posts

    Posted 14 Oct 2018 Link to this post

    Hi Rama,

    RadEditor cannot run macros, for three major reasons:

    • the context is completely different so the code necessary is completely different
    • this is a security issue
    • there is no standard conversion format for converting MS Word macros from HTML/JavaScript

    With this in mind, I can suggest you consider one or more of the following options:

    • create your own templates that contain the necessary JavaScript (note that such scripts will also execute when the user previews the template)
    • include the desired script in the editor content or on the page
    • create a custom content filter to do the necessary work

     


    Regards,
    Marin Bratanov
    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. Ramakrishna
    Ramakrishna avatar
    10 posts
    Member since:
    Feb 2012

    Posted 06 Nov 2018 Link to this post

    Thanks for the reply. I am using the custom dialog feature to mimic the macro functionality in the editor. that looks close to my requirement. using the custom dropdowns to show list of macros and user can choose one from the list and will be prompted for some input (if required for the chosen macro) using custom dialog box and once the input is provided, document will be updated with some content accordingly. only problem with this is that each dialog requires a separate ASPX page. need to find out if I can dynamically insert HTML without having so many pages.Please let me know if there is any better way to implement this. Thanks in advance.

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5897 posts

    Posted 07 Nov 2018 Link to this post

    Hello Ramakrishna,

    You can create custom tools in the editor that open your own dialogs, for example, RadWindow instances whose ContentTemplate is used to host your controls/logic. Instead of calling  editor.showExternalDialog(), you can show the desired RadWindow, and then upon the desired user action (e.g., selection from a dropdown or a button click), directly call the pasteHtml() method of the editor, without relying on callback functions.

    Here's a basic example:

    <telerik:RadEditor RenderMode="Lightweight" runat="server" ID="re1">
        <Tools>
            <telerik:EditorToolGroup>
                <telerik:EditorTool Name="InsertSpecialLink" Text="Insert Special Link" />
            </telerik:EditorToolGroup>
        </Tools>
        <Content>       
    Sample Content  
        </Content>
    </telerik:RadEditor>
     
    <telerik:RadWindow runat="server" ID="rw1" RenderMode="Lightweight" Modal="true" Behaviors="Close, Move" Title="Insert Custom Link">
        <ContentTemplate>
            <asp:TextBox runat="server" ID="tb1" />
            <asp:Button Text="paste contents" ID="button1" OnClientClick="pasteInEditor(this); return false;" runat="server" />
        </ContentTemplate>
    </telerik:RadWindow>
     
    <script type="text/javascript">
        function getEditor() {
            return $find("<%=re1.ClientID%>");
        }
        function getCustomLinkDialog() {
            return $find("<%=rw1.ClientID%>");
        }
        function pasteInEditor(btn) {
            var tbValue = $telerik.$(btn).parent().find("input").first().val();//one way to get the value through traversing the DOM
            var editor = getEditor();
            editor.pasteHtml(String.format("<a href='{0}' target='{0}' class='{0}'>{0}</a> ", tbValue));
            getCustomLinkDialog().close();
        }
        Telerik.Web.UI.Editor.CommandList["InsertSpecialLink"] = function (commandName, editor, args) {
            //sample logic for selecting and creating an anchor, taken from demo
            var elem = editor.getSelectedElement(); //returns the selected element.           
            if (elem) {
                if (elem.tagName == "A") {
                    editor.selectElement(elem);
                    argument = elem;
                }
                else {
                    var content = editor.getSelectionHtml();
                    var link = editor.get_document().createElement("A");
                    link.innerHTML = content;
                    argument = link;
                }
            }
            getCustomLinkDialog().show();
        };
    </script>


    Regards,
    Marin Bratanov
    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