6

In javascript I have a string, containing an SpreadsheetML file (excel xml)

I want to open a new window, and write this data to it, but have it open as excel.

Can I do that from javascript?

CaffGeek
  • 21,856
  • 17
  • 100
  • 184

1 Answers1

5

Yes, you can do that with a data URL,. First, encode the document as base64. Then, use the following URL as source of your window:

var mtype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var url = 'data:' + mtype + ';base64,' + base64data;
window.open(url);

This will require a modern browser.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469
  • Note, this will NOT work in IE. According to: https://developer.mozilla.org/en-US/docs/data_URIs, Internet Explorer 8 and above only supports data URIs for images in CSS, , and . So IE doesn't understand the content-type. – valdetero Aug 14 '13 at 23:02
  • Yes, as of IE 11, there's no full support for data URIs. Follow the [link in the answer](http://caniuse.com/datauri) to see current browser support. IE [does support](http://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx) the content-type parameter, just not the content type for spreadsheet documents (in data URIs). – phihag Aug 15 '13 at 09:37