2

Trying to search for a way to send an HTML table to Excel, I came across this fiddle

window.open('data:application/vnd.ms-excel,' + $('#whatever').html());

I was surprised to find out it was just that simple and I was wondering if anyone could explain how this works. The documentation for window.open doesn't appear to list an explanation under msdn https://msdn.microsoft.com/en-us/library/windows/apps/hh453415.aspx or mozilla developer network https://developer.mozilla.org/en-US/docs/Web/API/Window/open

It could be that I'm not phrasing my question correctly that's preventing me from finding an answer, but I guess I'm just curious how I can utilize this in the future to export html to excel and other file formats or if I shouldn't touch it(for instance if it's something that was abandoned and should never be used)

I've also looked at several other posts such as JavaScript table export to excel and export to excel using javascript and though they may answer the questions, I'm asking specifically about what's happening in the above code because it's so simple and concise.

Community
  • 1
  • 1
zfrisch
  • 8,474
  • 1
  • 22
  • 34
  • this will help with your googling https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs – Prinzhorn Feb 02 '16 at 19:45
  • 1
    excel opens HTML files with tables as though they were xls files. window.open() display an HTML page, or downloads non-html pages, which is what jQuery tells the popup it has. the jQuery part simply grabs the html of a table. put them all together, and viola. – dandavis Feb 02 '16 at 20:13
  • excellent. thank you gentleman – zfrisch Feb 02 '16 at 20:23

0 Answers0