I'm trying to export html table to excel in javascript, but when i click on export button, it exports successfully and direction of table is changed from right to left to left to right. How can I change this option in javascript to be exported right to left.
我正試圖在javascript中將html表導出為excel,但是當我點擊導出按鈕時,它成功導出並且表的方向從右向左變為從左到右。如何在javascript中更改此選項以從右向左導出。
This is my JS function:
這是我的JS功能:
function tablesToExcel(id) {
var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel" lang="fa">';
tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>';
tab_text = tab_text + '<x:Name>Report Sheet</x:Name>';
//tab_text = tab_text + '<x:Direction><x:right-to-left></x:right-to-left></x:Direction>';
tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';
tab_text = tab_text + "<table border='1px' dir='rtl'>";
tab_text = tab_text + $('#'+id).html();
tab_text = tab_text + '</table></body></html>';
var data_type = 'data:application/vnd.ms-excel';
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
if (window.navigator.msSaveBlob) {
var blob = new Blob([tab_text], {
type: "application/csv;charset=utf-8;"
});
navigator.msSaveBlob(blob, 'Report file.xls');
}
}
else {
$('#test').attr('href', data_type + ', ' + encodeURIComponent(tab_text));
$('#test').attr('download', 'Report file.xls');
}
}
}
1
according to SpreadsheetML in order to specify RTL for a sheet you should write this inside your WorkSheet:
根據SpreadsheetML為了指定工作表的RTL,你應該在工作表中寫這個:
<x:worksheet><x:sheetViews><x:sheetView rightToLeft=1></x:sheetView></x:sheetViews></x:worksheet>
Haven't tried it myself though, here is a reference to "worksheet" object, you can see for yourself https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.worksheet.aspx
雖然沒有嘗試過,這里是對“工作表”對象的引用,你可以自己看看https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.worksheet.aspx
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/08/30/81643062f7c3dfe98a1ec02f6ad431c8.html。