zoukankan      html  css  js  c++  java
  • word文档----to——html

    <html>
    
    <head>
    
    <title>Word2Html</title>
    
    <script language="javascript">
    
    function convert2html(){
    
    var htt;
    
    htt=document.getElementById("word").innerHTML;
    console.log(htt);
    
    htt = htt.replace(/</?SPAN[^>]*>/gi, "" );
    
            // Remove Class attributes
    
            htt = htt.replace(/<(w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
            // Remove Style attributes
    
            htt = htt.replace(/<(w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
    
            // Remove Lang attributes
    
            htt = htt.replace(/<(w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
            // Remove XML elements and declarations
    
            htt = htt.replace(/<\??xml[^>]*>/gi, "") ;
    
            // Remove Tags with XML namespace declarations: <o:p></o:p>
    
            htt = htt.replace(/</?w+:[^>]*>/gi, "") ;
    
            // Replace the &nbsp;
    
            htt= htt.replace(/&nbsp;/, " " );
    
            //我的replace
            //
            htt= htt.replace(/align="justify"/gi, 'class="justify"');
    
            // Transform <P> to <DIV>
    
            var re = new RegExp("(<P)([^>]*>.*?)(</P>)","gi") ;        // Different because of a IE 5.0 error
    
            htt = htt.replace( re, "<div$2</div>" ) ;
    
        html.value = htt;     
    
    }
    
    // 清除WORD冗余格式并粘贴
    
    function cleanAndPaste(  ) {
            // Remove all SPAN tags
    
            htt = htt.replace(/</?SPAN[^>]*>/gi, "" );
    
            // Remove Class attributes
    
            htt = htt.replace(/<(w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
            // Remove Style attributes
    
            htt = htt.replace(/<(w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
    
            // Remove Lang attributes
    
            htt = htt.replace(/<(w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
            // Remove XML elements and declarations
    
            htt = htt.replace(/<\??xml[^>]*>/gi, "") ;
    
            // Remove Tags with XML namespace declarations: <o:p></o:p>
    
            htt = htt.replace(/</?w+:[^>]*>/gi, "") ;
    
            // Replace the &nbsp;
    
            htt = htt.replace(/&nbsp;/, " " );
    
            // Transform <P> to <DIV>
    
            var re = new RegExp("(<P)([^>]*>.*?)(</P>)","gi") ;        // Different because of a IE 5.0 error
    
            htt = htt.replace( re, "<div$2</div>" ) ;
    
            html.value = htt;  
    }
    
    </script>
    
    </head>
    
    <body>
    
    <p>请在这里贴入WORD文件内容
    
    <div style="border:1 outset #ffffff; overflow:auto;80%;height:50%" id="word" contenteditable></div>
    
    <input type="button" value="转换成HTML" onClick="convert2html()">
    <input type="button" value="清除格式" onClick="cleanAndPaste()">点击后把生成的代码,全选后复制,并粘贴到wiki的编辑框中<br>
    
    <textarea cols="115" rows="18" id="html"></textarea><br>
    
    注意:您的浏览器必须是IE5.5后以上,否则无法插入文字!
    
    </body></html>
  • 相关阅读:
    BZOJ 3992: [SDOI2015]序列统计
    BZOJ 4836: [Lydsy1704月赛]二元运算
    2.Add Two Numbers
    [RN] React Native 调试技巧
    [商业世界] 商业三流:信息流、资金流、物流
    [杂谈] 记 程序员 对抗失眠烦恼的 大法
    [未来成长]让写作成为一种生活习惯
    [未来成长] 分享:《麦肯锡教我的写作武器》如何写出一篇具有逻辑表现力的文案
    [未来成长] 分享:在腾讯的八年,我的职业思考
    [PHP]:AES对称加密 -- 支持PHP7
  • 原文地址:https://www.cnblogs.com/beimingbingpo/p/9847868.html
Copyright © 2011-2022 走看看