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

Import from Word

2 Answers 65 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 28 Sep 2016, 01:26 PM

Hi there, I'm using some code like this to import from Word.

 

            Using fileStream As New FileStream(Server.MapPath(FilePath), FileMode.Open, FileAccess.Read)
                EditorContent.LoadDocxContent(fileStream)
            End Using

In principle this works fine. However, if text has been formatted as Heading 3 in Word, then it comes through as <p>My text</p> instead of <h3>My text</h3>.

However, if I copy/paste from Word into the editor, then the <h3> tags are preserved. Any ideas why the import is not preserving the <h3> tags?

2 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 28 Sep 2016, 02:07 PM
Hi Julian,

The import and paste from Word options are based on two different technologies.

The paste process is controlled by the browser and the operating system and the editor is just a consumer of the clipboard content, which only strips the unwanted formatting.

While the importation of DOCX is actually a conversion from DOCX syntax to HTML content with the help of the Telerik RadWordsProcessing library.

We are aware of the H -> P tag problem and we could propose the following solution for it: You can implement a custom client-side function that replaces the paragraphs having special classes TelerikHeading with the corresponding H elements with jQuery:

Copy Code
<telerik:RadEditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad">
</telerik:RadEditor>
 
<script type="text/javascript">
    function OnClientLoad(editor, args) {
        fixHeadings(editor.get_contentArea());
    }
 
    function fixHeadings(content) {
        var $ = $telerik.$;
 
        for (var i = 1; i <= 6; i++) {
            var headings = $(content).find("p.TelerikHeading" + i.toString());
 
            headings.each(function (index, item) {
                var element = $(item);
                var newH = $("<h" + i + "></h" + i + ">", {
                    html: element.html()
                });
 
                element.replaceWith(newH);
            });
        }
    };
</script>



Best regards,
Rumen
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Julian
Top achievements
Rank 1
answered on 28 Sep 2016, 02:41 PM
Great, thanks.
Tags
Editor
Asked by
Julian
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Julian
Top achievements
Rank 1
Share this question
or