Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否将html表导出到客户端的ppt?_Javascript_Jquery_Plugins_Jquery Plugins_Export - Fatal编程技术网

Javascript 是否将html表导出到客户端的ppt?

Javascript 是否将html表导出到客户端的ppt?,javascript,jquery,plugins,jquery-plugins,export,Javascript,Jquery,Plugins,Jquery Plugins,Export,我想知道我们是否有任何jquery或javascript解决方案可以将html表格转换为powerpoint。我得到的唯一解决方案是。这里我们有所有的导出选项,但我只想要powerpoint的解决方案。我可以使用Html表导出,但我关心的是,对于一个导出,我应该使用整个插件。是否有仅用于ppt的示例代码?如果您关心库的大小,那么您最好自己修改js库。取出可能与power point函数无关的代码片段。然后进行测试,逐步使库越来越小。除此之外,我没有发现任何明显的地方已经有了这个解决方案 通过执行

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

如果您关心库的大小,那么您最好自己修改js库。取出可能与power point函数无关的代码片段。然后进行测试,逐步使库越来越小。除此之外,我没有发现任何明显的地方已经有了这个解决方案

通过执行上述练习,我能够将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);
/*麻省理工学院许可证(MIT)
版权所有(c)2014https://github.com/kayalshri/
特此准许。。。。
....
*/
(函数($){
$.fn.extend({
tableExport:功能(选项){
var默认值={
分隔符:',',
忽略列:[],
tableName:'yourTableName',
类型:'powerpoint',
逃避:'真',
htmlContent:“假”,
控制台记录:“错误”
};
var options=$.extend(默认值,选项);
var el=这个;
如果(defaults.type==“powerpoint”){
//log($(this.html());
var excel=“”;
//标题
$(el).find('thead').find('tr').each(function(){
excel+=”;
$(this).filter(':visible').find('th').each(函数(索引、数据){
如果($(this.css('display')!='none'){
if(默认值.ignoreColumn.indexOf(index)=-1){
excel++=“”+parseString($(this))+“”;
}
}
}); 
excel+='';
});                 
//行与列
var rowCount=1;
$(el).find('tbody').find('tr').each(function(){
excel+=”;
var colCount=0;
$(this).filter(':visible').find('td').each(函数(索引,数据){
如果($(this.css('display')!='none'){
if(默认值.ignoreColumn.indexOf(index)=-1){
excel++=“”+parseString($(this))+“”;
}
}
colCount++;
});                                                         
行计数++;
excel+='';
});                 
excel+=''
if(defaults.consoleLog==“true”){
console.log(excel);
}
var excelFile=“”;
excelFile+=“”;
excelFile+=“”;
excelFile+=“”;
excelFile+=“”;
excelFile+=excel;
excelFile+=“”;
excelFile+=“”;
var base64data=“base64,”+$.base64.encode(excelFile);
open('data:application/vnd.ms-'+defaults.type+';filename=exportData.doc;'+base64data);
}
函数解析字符串(数据){
if(defaults.htmlContent==“true”){
content_data=data.html().trim();
}否则{
content_data=data.text().trim();
}
if(defaults.escape==“true”){
内容数据=转义(内容数据);
}
返回内容和数据;
}
}
});
})(jQuery);

您可以使用此代码替换tableExport.js文件,并通过将powerpoint作为类型传入来以相同的方式调用它,或者您可以忽略它,它仍然可以工作

您可以使用相同的解决方案,通过修改JS文件,只使用与MS Office相关的部分。实际上,转换Porwerpoint表的函数与转换Excel和Word的函数相同

要做到这一点,您只需要jquery.base64.js文件和tableExport.js文件,但需要更改以下文件的所有tableExport.js内容:

/*The MIT License (MIT)
Copyright (c) 2014 https://github.com/kayalshri/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

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

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

                if(defaults.type == 'excel' || defaults.type == 'doc'|| 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);
/*麻省理工学院许可证(MIT)
版权所有(c)2014https://github.com/kayalshri/
特此向任何获得副本的人免费授予许可
本软件和相关文档文件(“软件”)的
在软件中不受限制,包括但不限于权利
使用、复制、修改、合并、发布、分发、再许可和/或销售
软件的副本,并允许向其提供软件的人员
按照以下条件提供:
上述版权声明和本许可声明应包含在
软件的所有副本或主要部分。
本软件按“原样”提供,无任何形式的明示或明示担保
默示,包括但不限于适销性保证,
适用于特定目的和非侵权。在任何情况下
作者或版权持有人应承担任何索赔、损害或其他责任
无论是在合同诉讼、侵权诉讼或其他诉讼中,由以下原因引起的责任:,
与本软件有关或与本软件的使用或其他交易有关
软件*/
(函数($){
$.fn.extend({
tableExport:功能(选项){
var默认值={
分隔符:',',
忽略列:[],