views:

42

answers:

1

Can I get some help interpreting / implementing the answers at: http://stackoverflow.com/questions/2006468/copy-paste-from-excel-to-a-web-page/2006789 please?

This was the most useful answer Google found for "Paste Excel to Web Page/Form" -- seems perfect but I can't get to work.

(Requirement is to give users an option to pre-populate information in Excel, and when ready to submit a request paste into a form on our server.)

I "inherited" a server at work with

WAMP 2.0
Apache 2.2.11
PHP 5.2.9

I'm fair with VBA in Excel. Newbie at PHP. Tutorial and basic forms working okay, using Eclipse IDE.

Tried code in answers -- d/l'd jquery and set the path in the code. Tutorial examples for jquery seem to work.

Tatu Ulmanen's answer gives me a Parse error on
"var data = $('input[name=excel_data]').val();"

Related to
// Insert into DOM
$('#excel_table').html(table);
?
Don't know what that means.

Mic's answer gives no error, but the convert button doesn't do anything.

Ideas / direction? Please?

A: 

Given that you're referring to my original answer, perhaps I can give you some insight on how it should work.

I had to make few changes to my original answer (textarea instead of input), but the full HTML required for that code to work is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">
    $(function() {
        $('textarea[name=excel_data]').keyup(function() {
            var data = $(this).val();
            var rows = data.split("\n");
            var table = $('<table />');    
            for(var y in rows) {
                var cells = rows[y].split("\t");
                var row = $('<tr />');
                for(var x in cells) {
                    row.append('<td>'+cells[x]+'</td>');
                }
                table.append(row);
            }
            $('#excel_table').html(table);
        });
    });
    </script>
</head>
<body>
    <textarea name="excel_data" /></textarea>
    <div id="excel_table"></div>
</body>
</html>

That code will generate a HTML table of whatever excel data you paste into the textarea.

Note that this does not require any PHP to work as it is. If you want to save the data, you must create a form that submits the data to a PHP script which will do similar parsing on the data inside excel_data field.

Now, when you paste something in the excel_data field from excel, the resulting table should appear in the excel_table div.

Tatu Ulmanen
Thank you Tatu, very much!
KingsKid360