将数据复制到剪贴板以粘贴到Excel中. [英] Copy data to clipboard to paste into excel.

查看:318
本文介绍了将数据复制到剪贴板以粘贴到Excel中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些代码以将一组数据复制到剪贴板,以便可以将其粘贴到excel中并保持表格格式.

目前,我正在通过javascript进行处理,数据到隐藏的html表中,然后从那里复制到剪贴板(下面显示的内容比其他任何东西都重要).

Im writing some code to copy a set of data to the clipboard, so it can be pasted into excel and keep a tabular format.

At the moment I am doing it through javascript, rendering the data into a hidden html table and copying it to clipboard from there (its shown below for refrerence more than anything else).

results = GetDataFromDB(..);
helper.RenderHtml("<textarea id='holdtext' style='display:none;'>");
helper.RenderHtml("<table>");
helper.RenderHtml("<tr><td>Item</td> <td>Location</td> <td>Quantity</td></tr>");
foreach (Row row in results)
{
   helper.RenderHtml("<tr>");
   helper.RenderHtml("<td>{0}</td>", row.GetString(0));
   helper.RenderHtml("<td>{0}</td>", row.GetString(1));
   helper.RenderHtml("<td>{0}</td>", row.GetInt(2));
   helper.RenderHtml("</tr>");
}
helper.RenderHtml("</table>");
helper.RenderHtml("</textarea><script>Copied = holdtext.createTextRange(); Copied.execCommand('Copy');</script>");


它运行得很漂亮-有点........
问题是它非常非常慢.
查询本身可能需要几秒钟才能运行,但是如果有100,000或更多的行,则整个数据检索,渲染和复制过程可能需要5分钟以上的时间.简单地将其直接绘制到屏幕上,然后手动选择/复制整个页面并以这种方式粘贴(实际上我不太明白为什么.)的方法实际上要快得多.数据实际上并不需要显示在屏幕上,以目前的方式呈现它似乎是非常多余的.


因此,我该如何将数据复制到


and it works beautifully - sort of........
The problem is that it is very, very slow.
The query itself takes maybe a few seconds to run, but the whole process of retreiving the data, rendering it and copying it can take 5 minutes+ if there are 100,000 or more rows. It is actually a lot quicker to simply draw it to screen directly and then manually select/copy the whole page and paste it that way (which i dont really understand why..)

But anyway i figured since the data doesnt actually need to be displayed on screen, it seems horribly redundant to render it in the way it is at the moment.


So, how can i go about copying my data into the clipboard, while keeping it in a table-like format when pasted into excel.

推荐答案



对于 与问题相关的问题 asp.net,请发布 至: .

谢谢,
Harry


这篇关于将数据复制到剪贴板以粘贴到Excel中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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