javascript - 在客户端将html表格导出到ppt?

标签 javascript jquery plugins jquery-plugins export

我想知道我们是否有任何 jquery 或 javascript 解决方案来将 html 表转换为 powerpoint。我得到的唯一解决方案是 html table export 。这里我们有所有导出选项,但我只想要 powerpoint 的解决方案。我可以使用 Html 表导出,但我担心的是,对于一次导出,我应该使用整个插件。有没有ppt的示例代码?

最佳答案

如果您担心库的大小,最好的办法是自行修改 js 库。取出可能与电源点功能无关的代码片段。然后进行测试,逐步使库越来越小。除此之外,我没有发现任何明显的地方已经有这个解决方案可用。

通过执行上面的练习,我能够将 tableExport.js 文件从 12kb 减少到 5kb(非最小化),同时仍然保持导出到 power-point 功能。

/*The MIT License (MIT)

Copyright (c) 2014 https://github.com/kayalshri/

Permission is hereby granted....
....
*/

(function($){
    $.fn.extend({
        tableExport: function(options) {
            var defaults = {
                    separator: ',',
                    ignoreColumn: [],
                    tableName:'yourTableName',
                    type:'powerpoint',
                    escape:'true',
                    htmlContent:'false',
                    consoleLog:'false'
            };

            var options = $.extend(defaults, options);
            var el = this;

            if(defaults.type == 'powerpoint'){
                //console.log($(this).html());
                var excel="<table>";
                // Header
                $(el).find('thead').find('tr').each(function() {
                    excel += "<tr>";
                    $(this).filter(':visible').find('th').each(function(index,data) {
                        if ($(this).css('display') != 'none'){                  
                            if(defaults.ignoreColumn.indexOf(index) == -1){
                                excel += "<td>" + parseString($(this))+ "</td>";
                            }
                        }
                    }); 
                    excel += '</tr>';                       

                });                 


                // Row Vs Column
                var rowCount=1;
                $(el).find('tbody').find('tr').each(function() {
                    excel += "<tr>";
                    var colCount=0;
                    $(this).filter(':visible').find('td').each(function(index,data) {
                        if ($(this).css('display') != 'none'){  
                            if(defaults.ignoreColumn.indexOf(index) == -1){
                                excel += "<td>"+parseString($(this))+"</td>";
                            }
                        }
                        colCount++;
                    });                                                         
                    rowCount++;
                    excel += '</tr>';
                });                 
                excel += '</table>'

                if(defaults.consoleLog == 'true'){
                    console.log(excel);
                }

                var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+defaults.type+"' xmlns='http://www.w3.org/TR/REC-html40'>";
                excelFile += "<head>";
                excelFile += "<!--[if gte mso 9]>";
                excelFile += "<xml>";
                excelFile += "<x:ExcelWorkbook>";
                excelFile += "<x:ExcelWorksheets>";
                excelFile += "<x:ExcelWorksheet>";
                excelFile += "<x:Name>";
                excelFile += "{worksheet}";
                excelFile += "</x:Name>";
                excelFile += "<x:WorksheetOptions>";
                excelFile += "<x:DisplayGridlines/>";
                excelFile += "</x:WorksheetOptions>";
                excelFile += "</x:ExcelWorksheet>";
                excelFile += "</x:ExcelWorksheets>";
                excelFile += "</x:ExcelWorkbook>";
                excelFile += "</xml>";
                excelFile += "<![endif]-->";
                excelFile += "</head>";
                excelFile += "<body>";
                excelFile += excel;
                excelFile += "</body>";
                excelFile += "</html>";

                var base64data = "base64," + $.base64.encode(excelFile);
                window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.doc;' + base64data);

            }

            function parseString(data){

                if(defaults.htmlContent == 'true'){
                    content_data = data.html().trim();
                }else{
                    content_data = data.text().trim();
                }

                if(defaults.escape == 'true'){
                    content_data = escape(content_data);
                }

                return content_data;
            }

        }
    });
})(jQuery);

您可以用这段代码替换您的 tableExport.js 文件,并通过传入 powerpoint 作为类型以相同的方式调用它,或者您可以省略它,它仍然有效。

关于javascript - 在客户端将html表格导出到ppt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561870/

相关文章:

javascript - React-router:将 props 传递给 es6 处理程序组件

javascript - 如何使用 JavaScript/jQuery 更改第二个背景图像 url

javascript - 是否可以获取 "current"或 "last"事件的事件对象,而不将其作为处理程序中的参数接收?

python - pytest - 使用另一个插件的插件

javascript - 在 Angular 的 ngIf 条件中使用拆分函数

javascript - 如果对话框为空,如何禁用按钮

javascript - 使用揭示模块模式从动态元素获取元素 ID

php - 创建自定义 joomla 验证码

plugins - 错误 : Configuration cannot be run until project has been synced

javascript - forEach 意外标记向现有数组添加新属性