To use excel components in this way, the client must have an excel program. The method is to extract the content of each td tag in the table as the content of a cell in an excel file.
1. Add a java script to the webpage.
Function AutomateExcel (tableid, unusecolumn)
{
// Obtain the excel component
Var oXL = new ActiveXObject ("Excel. Application ");
// Create a workbook
Var oWB = oXL. Workbooks. Add ();
Var oSheet = oWB. ActiveSheet;
Var table = document. getElementById (tableid );
Var hang = table. rows. length;
Var lie = table. rows (0). cells. length;
For (I = 0; I {
For (j = 0; j <lie-unusecolumn; j)
{
OSheet. Cells (I 1, j 1). value = table. rows (I). cells (j). innerText;
}
}
OXL. Visible = true;
OXL. UserControl = true;
}
2. Add the export button.
<Input class = "Noprint" type = "Button" onclick = "AutomateExcel (ordertable, 0);" value = "Export">
The first parameter of the AutomateExcel function is the ID of the table to be exported. The second parameter indicates the number of columns to be ignored at the end of the table during export. If this parameter is not required, set it to '0'