将HTML导出表格到Excel右到左

6

我想要将一个表格导出到Excel,我已经可以做到了,但是表格是从左到右的,我希望它是从右到左的。当然,我可以手动地进行设置(页面布局 -> 工作表从右到左),但我希望它能够自动完成。

我正在使用 jquery.table2excel.js 进行导出:

//table2excel.js
(function($, window, document, undefined) {
    var pluginName = "table2excel",
        defaults = {
            exclude: ".noExl",
            name: "Table2Excel"
        };

    // The actual plugin constructor
    function Plugin(element, options) {
        this.element = element;
        // jQuery has an extend method which merges the contents of two or
        // more objects, storing the result in the first object. The first object
        // is generally empty as we don't want to alter the default options for
        // future instances of the plugin
        this.settings = $.extend({}, defaults, options);
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }

    Plugin.prototype = {
        init: function() {
            var e = this;
            e.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>";
            e.template += "<x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions>";
            e.template += "<x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>";
            e.tableRows = "";

            // get contents of table except for exclude
            $(e.element).find("tr").not(this.settings.exclude).each(function(i, o) {
                e.tableRows += "<tr>" + $(o).html() + "</tr>";
            });
            this.tableToExcel(this.tableRows, this.settings.name);
        },
        tableToExcel: function(table, name) {
            var e = this;
            e.uri = "data:application/vnd.ms-excel;base64,";
            e.base64 = function(s) {
                return window.btoa(unescape(encodeURIComponent(s)));
            };
            e.format = function(s, c) {
                return s.replace(/{(\w+)}/g, function(m, p) {
                    return c[p];
                });
            };
            e.ctx = {
                worksheet: name || "Worksheet",
                table: table
            };
            window.location.href = e.uri + e.base64(e.format(e.template, e.ctx));
        }
    };

    $.fn[pluginName] = function(options) {
        this.each(function() {
            if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName, new Plugin(this, options));
            }
        });

        // chain jQuery functions
        return this;
    };

})(jQuery, window, document);

我认为问题出在WorksheetOptions区域,但我无法弄清楚具体是什么。
HTML代码很简单,只是填充表格,并使用TableSorter.js实现排序功能。
谢谢。
1个回答

4
 <x:WorksheetOptions><x:DisplayRightToLeft/> </x:WorksheetOptions>

你可以在这里查看更多选项:点击此处。涉及到IT技术相关内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接