javascript - html 从右到左导出表格到 excel

标签 javascript jquery html excel export-to-excel

我正在尝试将表格导出到 excel,我可以做到,但是工作表是从左到右的,我希望它是从右到左的。当然我可以手动完成(Page Layout -> Sheet right-to-left),但我希望它是自动的。 我正在使用 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 启用排序。

谢谢

最佳答案

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

您可以看到更多选项:here

关于javascript - html 从右到左导出表格到 excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28544902/

相关文章:

javascript - QWebChannel 将空 QVariant POD 结构发送到 JavaScript

jquery - 如何加载大尺寸图像以便以后使用它作为 jQuery 的背景图像悬停效果?

php - 如何在php mysql中显示依赖于下拉子类别的父类别

javascript - jQuery Select2 占位符不起作用

html - 使用 CSS 和 html 使一个 Div 显示在整个浏览器中

javascript - slick.js 幻灯片的宽度在哪里计算?

html - 什么会导致 Chrome 自动填充停止工作?

javascript - 用于旋转下拉菜单的 Jquery/Javascript

javascript - 如何在表格中动态添加2行

javascript - 如何通过 onselect of materialize css 的自动完成元素触发事件