Skip to content

Instantly share code, notes, and snippets.

@Millsky
Created April 13, 2016 14:07
Show Gist options
  • Save Millsky/fb9e37d69c9698221ff45679db4aa8ef to your computer and use it in GitHub Desktop.
Save Millsky/fb9e37d69c9698221ff45679db4aa8ef to your computer and use it in GitHub Desktop.
function convertToIntArray(hex){
var bytes = [],
str;
for(var i=0; i<hex.length-1;i+=2){
bytes.push(parseInt(hex.substr(i, 2), 16))
}
return bytes;
}
var hex =
"504b03040A0000000000c37c8c4800000000000000000000000008000000746573742e747874504b010214000a0000000000c37c8c48000000000000000000000000080024000000000000002000000000000000746573742e7478740a0020000000000001001800d068f6d4f294d101d068f6d4f294d101d068f6d4f294d101504b050600000000010001005a000000260000000000";
var bytes = convertToIntArray(hex);
options = {};
options.fileName = "asd";
var ab = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes[i];
}
var b = new Blob([ia], {type: "application/octet-stream"});
var url = window.URL.createObjectURL(b),
a = document.createElement("a");
document.body.appendChild(a);
a.href = url;
a.download = options ? options.fileName + "" : "excelReport.xls";
a.click();
@Millsky
Copy link
Author

Millsky commented Apr 13, 2016

Downloads a zip file in your browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment