Bonjour messieurs,
Juste une autre manière d'encoder un contenu pour un fichier, et ensuite le proposer au téléchargement/ouverture, avec la méthode "blob":
SaveAs('xls', 'MonFichier');
function SaveAs(FileFormat, FFilename)
{
var ContentXLS = '\ufeff'+
'<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">'+
'<head>'+
'<!--[if gte mso 9]>'+
'<xml>'+
'<x:ExcelWorkbook>'+
'<x:ExcelWorksheets>'+
'<x:ExcelWorksheet>'+
'<x:Name>'+oToolName.BOMViewer+'</x:Name>'+
'<x:WorksheetOptions>'+
'<x:DisplayGridlines/>'+
'</x:WorksheetOptions>'+
'</x:ExcelWorksheet>'+
'</x:ExcelWorksheets>'+
'</x:ExcelWorkbook>'+
'</xml>'+
'<!--[endif]-->'+
'</head>'+
'<body>'+
$Buffer.replace(/(<table class="fileinfos">.*<\/table>.*<\/p>)|(<th class="checkbox">.*<\/a><\/th>)|(<td><input name="checkbox_[a-z0-9\- ]{1,}" type="checkbox" \/><\/td>)/gmi, '').replace(/<span class="[a-z]{1,}" title="([a-z0-9 \(\)]{1,})"><\/span>/gmi, ' $1').replace(/<tr class="([a-z]{1,})"><td>/gmi, '<tr><td>$1 - ')+
'</body>'+
'</html>',
ContentHTML = '<!DOCTYPE html><html>'+Head+'<body><div id="Retry"><a href="#Retry">'+$('#Retry a').html()+'</a><div><h1>'+oToolName.BOMViewer+'</h1><p>This page has been generated automatically by '+oToolName.BOMViewer+' '+Tool_v+'</p></div></div><h1>'+$('h1').html()+'</h1>'+$Buffer+Script+'</<body></html>',
HrefVal = false,
ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/),
ieEDGE = navigator.userAgent.match(/Edge/g),
ieVer= ((ie11) ? 11 : (ieEDGE ? 12 : -1));
switch(FileFormat)
{
case 'xls':
var typemime = 'application/vnd.ms-excel',
pointer = 'savexls',
extension = 'xls',
content = ContentXLS;
break;
default:
var typemime = 'text/html',
pointer = 'savehtml',
extension = 'html',
content = ContentHTML;
break;
}
if(Blob !== undefined)
{
var blob = new Blob([content], {type: typemime});
HrefVal = URL.createObjectURL(blob);
}
else
{
HrefVal = 'data:text/plain,'+encodeURIComponent(content);
}
if(ie11)
{
window.navigator.msSaveOrOpenBlob(blob, FFilename+'.'+extension);
}
else
{
$('#'+pointer).prop({
'href' : HrefVal,
'download' : FFilename+'.'+extension,
'target' : '_blank'
});
}
}
Ca n'apporte pas grand chose au bazard, mais si ça peut être utile à certain