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

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

3 Answers 27 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ramakrishna
Top achievements
Rank 1
Ramakrishna asked on 12 Oct 2018, 12:15 PM

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

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 14 Oct 2018, 08:16 PM
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.
0
Ramakrishna
Top achievements
Rank 1
answered on 06 Nov 2018, 07:41 AM

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.

0
Marin Bratanov
Telerik team
answered on 07 Nov 2018, 05:31 PM
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.
Tags
Editor
Asked by
Ramakrishna
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Ramakrishna
Top achievements
Rank 1
Share this question
or