Shr*_*Pai 10 javascript jquery plugins export jquery-plugins
我想知道我们是否有任何jquery或javascript解决方案将html表转换为powerpoint.我得到的解决方案是html表导出.这里我们有所有的导出选项,但我想只为powerpoint解决方案.我可以使用Html表导出,但我担心的是,对于一个导出我应该使用整个插件.是否只有ppt的示例代码?
如果图书馆的大小是您关心的问题,那么您最好的选择就是自己修改js库.取出可能与功率点功能无关的代码片段.然后进行测试,逐步使库变得越来越小.除此之外,我没有发现任何明显已有此解决方案的地方.
通过执行上面的练习,我能够将tableExport.js文件从12kb变为5kb(非最小化),同时仍然保持导出到功率点功能.
/*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);
Run Code Online (Sandbox Code Playgroud)
您可以使用此代码替换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);
Run Code Online (Sandbox Code Playgroud)
可以删除所有其他文件,包括jspdf文件夹.
这样您就可以将表导出为excel,doc和PowerPoint格式(实际上,当导出到doc和powerpoint时,您所做的是在文档中嵌入Excel电子表格,因此插件对于所有三种格式都是相同的)
以与原始插件相同的方式使用插件
| 归档时间: |
|
| 查看次数: |
4029 次 |
| 最近记录: |