SheetJSHis dudeness提出了一个问题:Copy/Paste from Excel to a web page,或许与您遇到的问题类似。
回答者Tatu Ulmanen给出了该问题的处理方式:
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 = $('
');for(var y in rows) {
var cells = rows[y].split("\t");
var row = $('
');for(var x in cells) {
row.append('
'+cells[x]+'');}
table.append(row);
}
// Insert into DOM
$('#excel_table').html(table);
So in essence, this script creates an HTML table from pasted Excel data.
希望本文对你有帮助,欢迎支持JavaScript中文网