html轉word


需求:在線填寫(動態)表單,將表單html轉成word保存在服務器

我在網上找了很久,大多數都是在后端各種正則,各種判斷控件什么的

偶然情況下我想到了一個方法:

一個隱藏的div存放你的html

遍歷控件將outerHTML替換成你的控件value即可,再把html傳給后端生成word

<div id="formsbmb">
    <div class="headData"><span><strong>申報書</strong></span></div> 
    <form id="form2">
        <div class="price-box" id="div_pagecontain" style="width:90%;padding:0px;margin-top:10px;margin-bottom:80px;">
            <div style=" min-height:470px; border:0px;width:100%;" id="doc_bill_content" name="doc_bill_content"></div>
        </div>
    </form>
    <div id="send" hidden></div>
</div>
var _conten = $("#doc_bill_content");

        $("#send").append(_conten);
        var input = $("#send input[type='text']");
        //var radio = $("#send input[type='radio']");
        //var checkbox = $("#send input[type='checkbox']");
        //var select = $("#send select");
        $.each(input, function (i, obj) {
            var value = $(obj).val();
            $(obj).prop("outerHTML", value);
        });
//剩余其他控件

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM