2

I'm having problem with my project for past two weeks and I'm just stuck. I have read numerous topics and forums regarding this and sill nothing.

What I want to do stands in title. I would like to make html page with table in which there would be input fields and some values, and when hit submit button all table data to be transferred to google spreadsheet.

Google spreadsheet don't have to exist on google drive. It could be created on submit and placed into google drive under name that is in field name.

    <!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<table>
    <th>Questions</th>
    <th>Answers</th>
    <th>Tip</th>
    <tr>
        <td>Question 1</td>
        <td><input id="answer1" value="" type="text" placeholder="answer here"></td>
        <td>Tip 1</td>
    </tr>
    <tr>
        <td>Question 2</td>
        <td><input id="answer2" value="" type="text" placeholder="answer here"></td>
        <td>Tip 2</td>
    </tr>
    <tr>
        <td>Question 3</td>
        <td><input id="answer3" value="" type="text" placeholder="answer here"></td>
        <td>Tip 3</td>
    </tr>
    <tr>
        <td colspan="3">Enter your name here:<input type="text" value="" id="name" placeholder="enter name"></td>
    </tr>
</table>
<button type="submit" id="subnutbtn">Submit your answers!</button>

</body>
</html>

This is what I read about this topic but it didn't worked for me.

Saving Form Data to Google Spreadsheets Using PHP and the Google Docs API,

Google Sheets as a Database – INSERT with Apps Script using POST/GET methods (with ajax example)

I was trying to do some of examples from links I posted but couldn't get them work. Probably coz google changed security police and out of date example.

Closest I got was to make a export to excel useing following function which make a copy of inputs in hidden table and then exports to user on submit:

function fillHidTable() {
            var htqf; //-- hidden field
            var rf; //-- retrieved field
            for (var i = 1; i < 32; i++) {
                rf = "htqf" + i;
                document.getElementById(rf).innerHTML = document.getElementById("Q" + i + "CALC").value;
            }
            tableToExcel('hidTable', 'Questions');
        }

        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))
            }
        })();

Next I was thinking to go a step further and try to export this excel to google drive, but don't really have an idea how. So any suggestions would be nice or link to examples.

flakes
  • 21
  • 1
  • 4
  • Ok, I updated my post with code what I have. Closest I got to what I wanted was that second link, but it is connected to only one spreadsheet, but I need for every user answering questions to make another or if same user comes back to fill some more answers to update current spreadsheet. – flakes Apr 09 '15 at 20:11
  • I understand that you are trying to use a table to get inputs from the user and enter that data into a sheet. Just to understand what you are trying to to do, have you considered using [Google Forms](https://developers.google.com/apps-script/guides/sheets#connecting_to_google_forms) to get that data and enter that into a sheet? It'll be an easier approach. – pointNclick Apr 23 '15 at 20:50

0 Answers0