Do not use the server-side technology, directly using JS to export the tabular data in the Web page as an Excel file, support all browsers;
The prerequisite is that the table data in the Web page must be formatted with the table label and no errors can be found.
<!DOCTYPE HTML><HTML><Head> <title>JavaScript exportexcel</title></Head><Body> <TableID= "Name"Border= "1"cellspacing= "0"cellpadding= "Ten"> <TR> <th>Name</th> <th>Age</th> <th>Job</th> </TR> <TR> <TD>Mike</TD> <TD>22</TD> <TD>Designer</TD> </TR> <TR> <TD>David</TD> <TD>28</TD> <TD>Programmer</TD> </TR> </Table> <BR> <Buttononclick= "Exportexcel (' name ');">Export to Excel</Button><Body><Script> /** * Export tables in HTML to Excel (compatible with all browsers) * @param {[type]} tableId [ID of table]*/ functionExportexcel (tableId) {varIDTMR; if (/msie|trident/i.test (navigator.useragent)) { varCurtbl=document.getElementById (tableId), OXL= NewActiveXObject ('Excel.Application'), oWB=oXL.Workbooks.Add (),//Create an Ax object ExcelXlsheet=Owb.worksheets (1), //Get Workbook Objectsel=Document.body.createTextRange (); //activating the current sheetSel.movetoelementtext (CURTBL);//Move the contents of the table into the TextRangeSel.execcommand ("Copy"); //copy content in TextRangeXlsheet. Paste (); //paste into active Exceloxl.visible= true; //set Excel Visible Properties Try { varfname=OXL.Application.GetSaveAsFilename ('Excel.xls', 'Excel Spreadsheets (*.xls), *.xls'); } Catch(e) {print ('Nested Catch caught' +e); } finally{owb.saveas (fname); Owb.close (SaveChanges= false); Oxl.quit (); OXL= NULL; IDTMR=SetInterval (function() {clearinterval (IDTMR); CollectGarbage (); }, 1); } } Else { functionBase64 (s) {returnBtoa (unescape (encodeURIComponent (s))}; functionformat (s, c) {returnS.replace (/{(\w+)}/G,function(M, p) {returnC[p]; }); }; varURI= 'Data:application/vnd.ms-excel;base64,', Template= '' + '' + '<!--[if GTE MSO 9]><xml><x:excelworkbook><x:excelworksheets><x:excelworksheet> <x:name>{worksheet}</x:name><x:worksheetoptions><x:displaygridlines/></x: Worksheetoptions></x:excelworksheet></x:excelworksheets></x:excelworkbook></xml> <! [endif]-->' + '' + '<body>' + '<table>{table}</table>' + '</body>' + '', CTX={worksheet:name|| 'Worksheet', Table:document.getElementById (tableId). InnerHTML}; Location.href=URI+base64 (Format (template, CTX)}}</Script></HTML>
JavaScript Exports Web page table data to Excel files