Announcement

Collapse
No announcement yet.

form to excel and upload

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • form to excel and upload

    How can i make a form, when you press the submit button it takes the content and paste it in a excel file, and after that it would upload it to a server, when a new file is uploaded it would send out a email notification to my mail so i can go and download it?

    so far i have only been able to find one where it makes the form content into a excel file, but it downloads it to the computer when i submit it, and that is not what i wanted

    what i have found so far: (im not taking credits for the code, i dont even know what half of it does) (credits)
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript">
    function fillHidTable(){
        var htqf; //-- hidden field
        var rf; //-- retrieved field
        for ( var i = 1; i < 7; 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"> Tilmeldingsskema</td>
        </tr>
        <tr>
            <td class="allbdrCenMid"> Nr.</td>
            <td class="allbdrLtMid"> Spørgsmål</td>
            <td class="allbdrCenMid"> Svar</td>
        </tr>
        <tr>
            <td class="allbdrCenTop"> 1</td>
            <td class="allbdrLtTop"> Navn</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"> 2</td>
            <td class="allbdrLtTop"> Skole</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"> 3</td>
            <td class="allbdrLtTop"> Adresse</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"> 4</td>
            <td class="allbdrLtTop"> CVR-nummer</td>
            <td class="allbdrCenMid">
                <input id="Q4CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q4CALC"/>
            </td>
        </tr>
    	<tr>
            <td class="allbdrCenTop"> 5</td>
            <td class="allbdrLtTop"> EAN</td>
            <td class="allbdrCenMid">
                <input id="Q5CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q5CALC"/>
            </td>
        </tr>
    	<tr>
            <td class="allbdrCenTop"> 6</td>
            <td class="allbdrLtTop"> E-mail</td>
            <td class="allbdrCenMid">
                <input id="Q6CALC" type="text" value="" class="nobdrCenMid" style="overflow:hidden; width:93% " name="Q6CALC"/>
            </td>
        </tr>
    	<tr>
            <td class="allbdrCenTop"></td>
            <td class="allbdrLtTop"> </td>
            <td class="allbdrCenMid"> æ=ae, ø=oe og å=aa</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>Nr.</th>
                <th>Spoergsmaal</th>
                <th>Svar</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>1</td>
                <td>Navn</td>
                <td id="htqf1">-</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Skole</td>
                <td id="htqf2">-</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Adresse</td>
                <td id="htqf3">-</td>
            </tr>
            <tr>
                <td>4</td>
                <td>CVR-Nummer</td>
                <td id="htqf4">-</td>
            </tr>
    		<tr>
                <td>5</td>
                <td>EAN</td>
                <td id="htqf5">-</td>
            </tr>
    		<tr>
                <td>6</td>
                <td>E-mail</td>
                <td id="htqf6">-</td>
            </tr>
            </tbody>
        </table>
    </div>
    
    <input type="button" onclick="fillHidTable()" value="Export Data to Excel">
    </body>
    </html>
    Last edited by skovd; 08-05-2015, 08:10 AM. Reason: forgot to give credits to the coder

  • #2
    What you have there is javascript and that will all run locally to your PC, not on the server. After you run that script, you will have to upload it.

    The only way to paste stuff in an excel file is if the excel file is a CSV file, other than that it will have to open excel locally on your PC then save it and then you can upload it with a different script.
    Have a Script or Snippet you want to share?

    WWW Standards: HTML 4.01,
    HTML 5, CSS2.1, CSS3, XHTML 1.0
    PHP Standards: PHP Standards

    Comment

    Working...
    X