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.
This is my JS function:
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');
    }
}
according to SpreadsheetML in order to specify RTL for a sheet you should write this inside your WorkSheet:
<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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With