我试图在javascript中将html表格导出为excel,但是当我点击导出按钮时,它会成功导出并且表格的方向从从右到左更改为从左到右。 如何在javascript中将此选项更改为从右向左导出。
这是我的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');
}
}
答案 0 :(得分:1)
根据SpreadsheetML为了指定工作表的RTL,你应该在工作表中写这个:
<x:worksheet><x:sheetViews><x:sheetView rightToLeft=1></x:sheetView></x:sheetViews></x:worksheet>
虽然没有尝试过, 这里是对“工作表”对象的引用,你可以自己看看 https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.worksheet.aspx