-1

I want to copy the HTML table from my page as rich text to clipboard and be ready to paste the contents in excel on a single click.

I found a awesome code in Stackoverflow Select a complete table with Javascript (to be copied to clipboard)

However, the above code will only select the content in the table. Can any one please help to tweak the code to make it to copy table as rich text (table cells contains color and need to be copied) and paste it in excel or any other compatible window.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user220987
  • 51
  • 1
  • 4
  • 5
    How ironic that this is tagged with "copy-paste". – Benjamin Gruenbaum May 17 '13 at 19:16
  • 5
    Hello! SO is a Q&A site, not a "please write the code for me" site. You should at least try to make the changes yourself. When asking good questions it really helps to [do your homework first](http://whathaveyoutried.com) – Dan Pichelman May 17 '13 at 19:16
  • 2
    the demo in the link you've provided does exactly that. Try http://jsfiddle.net/UKHaq/ and paste it in MS Word. – SachinGutte May 17 '13 at 19:17
  • Sorry for the tag guys. Please don't vote down. I'm a learner. – user220987 May 17 '13 at 19:22
  • You shouldn't be asking someone to tweak the code for you. You should either A. Do research attempt it yourself and ask for help here if you get stuck or B. Pay someone to do it on a Freelancer site (such as odesk, guru, freelancer, etc). – Travis Pessetto May 17 '13 at 19:24
  • ok guys.. I'm removing the question thread. Sorry. I guess, I asked in work words. – user220987 May 17 '13 at 19:25
  • Yes Travis, I tried a lot and learn't a lot from this site. Hence I posted the question, since I was not able to understand. – user220987 May 17 '13 at 19:26
  • It would help if you stated what you have tried in your question. How far did you get when you got stuck? – Travis Pessetto May 17 '13 at 19:28
  • 1
    I can select the entire table in the page. Unable to make it copy. Copied.execCommand(“Copy”); is not working. hence I posted. – user220987 May 17 '13 at 19:30

1 Answers1

2

Because a browser is a sand-boxed environment is usually rendered impossible by most browsers (IE a known exception) to copy to the system's clipboard, which is what you want without the aid of flash. You can use ZeroClipboard to aid in this if you still want to copy. Otherwise I suggest instructing users to press Ctrl+C to copy.

See this related post: HTML5 alternative to flash-based ZeroClipboard for safe copying of data to clipboard?.

Community
  • 1
  • 1
Travis Pessetto
  • 3,260
  • 4
  • 27
  • 55