Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy/Paste from Excel to a web page

Is there a standard way or library to copy and paste from a spreasheet to a web form? When I select more than one cell from Excel I (obviously) lose the delimiter and all is pasted into one cell of the web form. Does it have to be done in VB? or could the processing be done once the paste action is started on the web form?

like image 208
His dudeness Avatar asked Jan 05 '10 14:01

His dudeness


People also ask

Can you pull data from Excel to website?

Excel is a spreadsheet application, but an Excel file can also serve as a database for your website if you can perform some basic programming. One of simplest ways to accomplish this is to create a PHP program, connect to your Excel file, pull the required data and display the HTML on your Web page.

How do I copy and paste into my Web browser?

3. Open your Web browser (such as Chrome), select the text in your browser's address bar and delete it. Press "Ctrl" and "V" simultaneously to paste the URL you just copied into the address bar. Press enter and the browser will take you to the URL address.


2 Answers

You don't lose the delimiters, the cells are separated by tabs (\t) and rows by newlines (\n) which might not be visible in the form. Try it yourself: copy content from Excel to Notepad, and you'll see your cells nicely lined up. It's easy then to split the fields by tabs and replace them with something else, this way you can build even a table from them. Here's a example using jQuery:

var data = $('input[name=excel_data]').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); }  // Insert into DOM $('#excel_table').html(table); 

So in essence, this script creates an HTML table from pasted Excel data.

like image 52
Tatu Ulmanen Avatar answered Oct 15 '22 03:10

Tatu Ulmanen


In response to the answer by Tatu I have created a quick jsFiddle for showcasing his solution:

http://jsfiddle.net/duwood/sTX7y/

HTML

<p>Paste excel data here:</p>   <textarea name="excel_data" style="width:250px;height:150px;"></textarea><br> <input type="button" onclick="javascript:generateTable()" value="Genereate Table"/> <br><br>     <p>Table data will appear below</p> <hr> <div id="excel_table"></div> 

JS

function generateTable() {     var data = $('textarea[name=excel_data]').val();     console.log(data);     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); }  // Insert into DOM $('#excel_table').html(table); } 
like image 20
dunderwood Avatar answered Oct 15 '22 05:10

dunderwood