ExcelファイルのAngularJSを変換します。名前の変更は、私は私が私のExcelファイルの名前を変更しなければならなかった状況で立ち往生しています
シナリオ:
私は、私はそれはのようにダウンロードしたファイルをダウンロードしたとき、私は成功してきたその部分は、問題がある、Excelファイルに表を変換した:「Download.xlsは」私はそれを名前を変更したい「MYExcel.xls "最も簡単な方法は、レバレッジにある
app.html
<button class="btn btn-link col-md-2" ng-click="exportToExcel('#tableToExport1')">Export</button>
app.js
$scope.exportToExcel=function(tableId){ // ex: '#my-table'
var exportHref=Excel.tableToExcel(tableId,'WireWorkbenchDataExport');
console.log(location.href)
$timeout(function(){location.href=exportHref;},100); // trigger download
}
Excel.service.js
.factory('Excel',function($window){
var uri='data:application/vnd.ms-excel;base64,',
template='<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>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
base64=function(s){return $window.btoa(unescape(encodeURIComponent(s)));},
format=function(s,c){return s.replace(/{(\w+)}/g,function(m,p){return c[p];})};
return {
tableToExcel:function(tableId,worksheetName){
var table=$(tableId),
ctx={worksheet:worksheetName,table:table.html()},
href=uri+base64(format(template,ctx));
console.log(ctx)
return href;
}
};
});
私は私 –
XLSX使用しかし、XLSのためによく働いていた場合、破損言って2つの非常に異なるファイル形式です。生成しているファイルに適合する拡張子を使用してください。 –
XLSとXLSXのためので細かい – Salketer