0

How can I copy the contents of an asp:Table to the clipboard so that it can be pasted in something like Excel?

I assume some sort of JavaScript is required?

For winforms it is easy enough using the Clipboard object but how about for asp.net?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript – Gage Mar 22 '13 at 17:51

2 Answers2

1

The problem with browsers is that clipboard access is often a privileged access so you end up needing something like Flash.

There's a nice library out there I used a couple of times called ZeroClipboard - https://github.com/jonrohan/ZeroClipboard

Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • So there is no quick JS way to do it? Well there is for simple text but how about for something complex like a table? – sd_dracula Mar 22 '13 at 17:50
  • There isn't a quick way to do it, you'd have to come up with the code to pull the table and format it yourself. – Lloyd Mar 22 '13 at 17:50
0

A technique I saw somewhere said to open a popup, copy the data into it, pre-select it, and tell the user to press CTRL+C. Sounds silly, but it is easy for the user and doesn't require any special privileges.

I started using it in a few sites and my users LOVE it. Everything is done in jQuery. Here's a screenshot from a transaction where users wanted to copy an HTML table into Excel. Clicking on a "Export to Excel" button produces this...

enter image description here

mr_plum
  • 2,448
  • 1
  • 18
  • 31