Js exports table contents to a simple instance of Excel
- 2020-03-29 23:50:26
- OfStack
function ExportToExcel(tableId) //Read each cell in the table into EXCEL & NBSP;
{
try{
var curTbl = document.getElementById(tableId);
var oXL = new ActiveXObject("Excel.Application");
//Create AX object excel& cake;
var oWB = oXL.Workbooks.Add();
//Gets the workbook object & NBSP;
var oSheet = oWB.ActiveSheet;
var lenRow = curTbl.rows.length;
//Gets the number of rows & NBSP;
for (i = 0; i < lenRow; i++)
{
var lenCol = curTbl.rows(i).cells.length;
//Gets the number of columns per row & NBSP;
for (j = 0; j < lenCol; j++)
{
oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
//Set the excel visibility property & NBSP;
}catch(e){
if((!+'/v1')){ //Internet explorer & NBSP;
alert(" Unable to start Excel Please make sure the computer is installed Excel!/n/n If installed Excel . "+" Please adjust IE The level of security. /n/n Specific operation: /n/n"+" tool - Internet options - security - Custom level - ActiveX Controls and plug-ins - For those not marked as safe to execute the script ActiveX Control initializes and executes the script - To enable the - determine ");
}else{
alert(" Please use the IE The browser does "import into EXCEL "Operation! "); // Convenient to set the security level, limit to Internet explorer & NBSP;
}
}
}
function ExportToExcel(tableId) //Read each cell in the table into EXCEL
{
try{
var curTbl = document.getElementById(tableId);
var oXL = new ActiveXObject("Excel.Application");
//Create the AX object excel
var oWB = oXL.Workbooks.Add();
//Gets the workbook object
var oSheet = oWB.ActiveSheet;
var lenRow = curTbl.rows.length;
//Gets the number of rows in the table
for (i = 0; i < lenRow; i++)
{
var lenCol = curTbl.rows(i).cells.length;
//Gets the number of columns per row
for (j = 0; j < lenCol; j++)
{
oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
//Set the excel visibility properties
}catch(e){
if((!+'/v1')){ //Ie browser
alert(" Unable to start Excel Please make sure the computer is installed Excel!/n/n If installed Excel . "+" Please adjust IE The level of security. /n/n Specific operation: /n/n"+" tool - Internet options - security - Custom level - ActiveX Controls and plug-ins - For those not marked as safe to execute the script ActiveX Control initializes and executes the script - To enable the - determine "); www.th7.cn
}else{
alert(" Please use the IE The browser does "import into EXCEL "Operation! "); // Convenient to set the security level, limit to Ie browser
}
}
}