1 回答

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
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);
以上代碼是jquery.tableExport插件中的部分實(shí)現(xiàn),
思路大致就是獲取表格里面的內(nèi)容,將數(shù)據(jù)以列表形式插入到excel中即可
當(dāng)然我覺(jué)得作為一個(gè)工程師,最重要一點(diǎn)不要重復(fù)造輪子,這對(duì)你的成長(zhǎng)并沒(méi)有任何幫助,所謂站在巨人的肩膀上,你才能看的更遠(yuǎn)、更寬,當(dāng)然除非你要深入研究開(kāi)發(fā)自己的產(chǎn)品
添加回答
舉報(bào)