将html表单数据导出为ex​​cel

时间:2013-09-09 18:17:57

标签: html excel html-form

我已经用Google搜索过,并且无法破解这个坚果。我有一个表单设置,让我的网站访问者订阅我的时事通讯。它只是向我的电子邮件发送一封电子邮件,然后我将它们添加到我的联系人中,然后将它们转发给他们。我需要的是能够将他们的联系信息放在Excel电子表格中,以便于访问我的订阅者列表。这可以用html完成吗? (我不知道任何js或其他任何可能需要的东西)

2 个答案:

答案 0 :(得分:2)

一种方法是创建一个php(或您的fav脚本语言)脚本,该脚本接受输入并将其附加到csv文件。然后将html表单发布到所述脚本中。您甚至可以设置一个cronjob,定期向您发送联系人的更新副本。

答案 1 :(得分:1)

实际上 - 有一种方法可以将HTML表单中的数据导出到Excel电子表格中。

在您的HTML表单中,您必须创建一个单独的表(可以隐藏它)。

BIG SECRET是: 在put id标签中,然后使用JavaScript将innerHTML替换为表单上用于收集所需数据的字段的值。

在这里查看JSFiddle:http://jsfiddle.net/MitchinThailand/589C4/

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fillHidTable(){
    var htqf; //-- hidden field
    var rf; //-- retrieved field
    for ( var i = 1; i < 5; i++ ) {
        rf = "htqf"+i;
        document.getElementById(rf).innerHTML = document.getElementById("Q"+i+"CALC").value;
    }
    tableToExcel('hidTable', 'Analysis Results');
}

var tableToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
    return function(table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
        window.location.href = uri + base64(format(template, ctx))
    }
})()
</script>

<title>HTML Form Data to Excel</title>

<style type="text/css" media="screen">
    .divCenMid{font-family:Arial,sans-serif;font-size:14pt;font-style:normal;font-weight:700;text-align:center;vertical-align:middle;margin:0;}
    .allbdrCenMid{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:center;vertical-align:middle;margin:0;}
    .allbdrCenTop{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:center;vertical-align:top;margin:0;}
    .allbdrLtMid{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:left;vertical-align:middle;margin:0;}
    .allbdrLtTop{border:.75pt solid windowtext;color:#000;font-family:Arial,sans-serif;font-size:10pt;font-style:normal;font-weight:400;text-align:left;vertical-align:top;margin:0;}

</style>

</head>

<body>

<table width= "565px" cellspacing="0" cellpadding="0" style="border-spacing:0;" id="QMSTable">
    <col width="25px"/>
    <col width="120px"/>
    <col width="360px"/>
    <col width="60px"/>
    <tr>
        <td class="divCenMid" colspan = "4"> QMS Assessment</td>
    </tr>
    <tr>
        <td class="allbdrCenMid"> No</td>
        <td class="allbdrCenMid"> Criteria</td>
        <td class="allbdrLtMid"> Question</td>
        <td class="allbdrCenMid"> Score</td>
    </tr>
    <tr>
        <td class="allbdrCenTop"> Q1</td>
        <td class="allbdrLtTop"> Quality Unit Independency</td>
        <td class="allbdrLtTop"> Do you have the Quality Unit?</td>
        <td class="allbdrCenMid">
            <input id="Q1CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q1CALC"/>
        </td>
    </tr>
    <tr>
        <td class="allbdrCenTop"> Q2</td>
        <td class="allbdrLtTop"> Apply PICS GMP</td>
        <td class="allbdrLtTop"> Which GMP regulation do you use?</td>
        <td class="allbdrCenMid">
            <input id="Q2CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q2CALC"/>
        </td>
    </tr>
    <tr>
        <td class="allbdrCenTop"> Q3</td>
        <td class="allbdrLtTop"> Deviation or Non-conformance</td>
        <td class="allbdrLtTop"> Do you have a deviation or non-conformance procedure?</td>
        <td class="allbdrCenMid">
            <input id="Q3CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q3CALC"/>
        </td>
    </tr>
    <tr>
        <td class="allbdrCenTop"> Q4</td>
        <td class="allbdrLtTop"> Complaint</td>
        <td class="allbdrLtTop"> Do you have a customer complaint procedure?</td>
        <td class="allbdrCenMid">
            <input id="Q4CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q4CALC"/>
        </td>
    </tr>
</table>

<div id="hidTable" style="display: none">
    <table id="testTable">
        <caption>Supplier Risk Analysis</caption>
        <colgroup></colgroup>
        <colgroup></colgroup>
        <colgroup></colgroup>
        <thead>
        <tr>
            <th>No.</th>
            <th>Question</th>
            <th>Score</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>Q1</td>
            <td>Do you have the Quality Unit?</td>
            <td id="htqf1">-</td>
        </tr>
        <tr>
            <td>Q2</td>
            <td>Apply PICS GMP?</td>
            <td id="htqf2">-</td>
        </tr>
        <tr>
            <td>Q3</td>
            <td>Do you have a deviation or non-conformance procedure?</td>
            <td id="htqf3">-</td>
        </tr>
        <tr>
            <td>Q4</td>
            <td>Do you have a customer complaint procedure?</td>
            <td id="htqf4">-</td>
        </tr>
        </tbody>
    </table>
</div>

<input type="button" onclick="fillHidTable()" value="Export Data to Excel">
</body>
</html>

如果您无法确定如何申请的详细信息,请与我联系。