Format Selected Table Rows For Pasting into Excel

by Bill Beckelman 2. January 2009 20:49

Back in November I wrote a post Add Copy to Clipboard Command To contextMenu.js Plugin Demo that copied the data from the selected table rows to the user’s clipboard. This method worked great unless you had a version of Flash Player higher than 9 installed due to a Security Change in Flash Player 10. I decided to mess around with this again today and come up with another method that might work that does not require any server side interaction.

I’m not really sure if this is an optimal solution (have to worry about popups being blocked), but I did get to mess around with some pretty interesting JavaScript and in the end it does work if your looking for another way.

The method I came up with does the following:

  1. Builds a string of the selected rows using a JavaScript string builder function I found here.
  2. The string is inserted in a hidden text area on the parent page (Note: I initially used a text input which worked fine in IE7 and FF3 but puked in Chrome 1.0).
  3. The child popup is opened.
  4. The child popup calls back to the parent and grabs the data from the hidden text area using: window.opener.document.getElementById('Hidden Text Area').value
  5. The data on the child is then selected to make it ready for the user to press ctrl-c or right click/copy using some cross browser JavaScript.

Demo (Tested in IE7, FF3 and Chrome)| Download (HTML/CSS/JS)

Screenshots of End Product:

  1. Format For Excel is clicked.

    image
  2. Popup loads with table data formatted cleanly, highlighted and ready for copying for pasting into Excel, Word, Outlook, etc.

image

Be sure to checkout the demo and download. Let me know what you think? Would you use this? If not, what would you do different?

 

  kick it on DotNetKicks.com

Tags:

ASP.NET | jQuery

Comments


About Me

I live and work in Salt Lake City, Utah. My background is in aviation. I have a degree in Aeronautical Science from Embry-Riddle Aeronautical University in Prescott, AZ. I have worked as a commercial airline pilot and most recently as a technical advisor for a charter airline.