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,195
  • 62
  • 50
  • 120
sd_dracula
  • 3,544
  • 23
  • 77
  • 147
  • 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
  • 27,966
  • 4
  • 78
  • 91
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

nunzabar
  • 2,334
  • 1
  • 13
  • 30