从 Excel 复制/粘贴到网页 [英] Copy/Paste from Excel to a web page

查看:61
本文介绍了从 Excel 复制/粘贴到网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有标准方法或库可以将电子表格复制并粘贴到网络表单?当我从 Excel 中选择多个单元格时,我(显然)丢失了分隔符,所有内容都被粘贴到 Web 表单的一个单元格中.它必须在VB中完成吗?或者是否可以在 Web 表单上开始粘贴操作后进行处理?

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?

推荐答案

你不会丢失分隔符,单元格由制表符 ( ) 分隔,行由换行符 ( ) 可能在表单中不可见.亲自尝试:将内容从 Excel 复制到记事本,您会看到单元格排列整齐.然后很容易按选项卡拆分字段并将它们替换为其他内容,这样您甚至可以从它们构建一个表.下面是一个使用 jQuery 的例子:

You don't lose the delimiters, the cells are separated by tabs ( ) and rows by newlines ( ) 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("
");

var table = $('<table />');

for(var y in rows) {
    var cells = rows[y].split("	");
    var row = $('<tr />');
    for(var x in cells) {
        row.append('<td>'+cells[x]+'</td>');
    }
    table.append(row);
}

// Insert into DOM
$('#excel_table').html(table);

所以本质上,这个脚本从粘贴的 Excel 数据创建了一个 HTML 表格.

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

这篇关于从 Excel 复制/粘贴到网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆