The code copy is as follows:
<html>
<head>
<script language="javascript" type="text/javascript">
function MakeExcel(){
var i,j;
try {
var xls = new ActiveXObject ( "Excel.Application" );
}
catch(e) {
alert("To print this table, you must install Excel spreadsheet software, and the browser must use "ActiveX controls", and your browser must allow the execution of controls. Please click [Help] to understand how to set the browser!");
return "";
}
xls.visible =true; //Set excel to visible
var xlBook = xls.Workbooks.Add;
var xlsheet = xlBook.Worksheets(1);
<!--Merge-->
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="Card issuance record";
// xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Interior.ColorIndex=5;//Set the background color to blue
// xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Font.ColorIndex=4;//Set the font color
// xlsheet.Rows(1). Interior .ColorIndex = 5;//Set the background color to blue. Set the background color Rows(1).Font.ColorIndex=4
<!--Set the line height-->
xlsheet.Rows(1).RowHeight = 25;
<!--Set font ws.Range(ws.Cells(i0+1,j0), ws.Cells(i0+1,j1)).Font.Size = 13 -->
xlsheet.Rows(1).Font.Size=14;
<!--Set Font Set the fonts of the selected area xlsheet.Range(xlsheet.Cells(i0,j0), ws.Cells(i0,j0)).Font.Name = "Bold" -->
xlsheet.Rows(1).Font.Name="Boldbody";
<!--Set the column width xlsheet.Columns(2)=14;-->
xlsheet.Columns("A:D").ColumnWidth =18;
<!--Set display characters instead of numbers-->
xlsheet.Columns(2).NumberFormatLocal="@";
xlsheet.Columns(7).NumberFormatLocal="@";
//Set the cell content to automatically wrap the line range.WrapText = true;
//Set the horizontal alignment of cell content range.HorizontalAlignment = Excel.XlHAlig.xlHAligCenter;//Set the vertical stacking method of cell content
//range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
//range.WrapText = true; xlsheet.Rows(3).WrapText=true Automatic wrapping
//Set the title bar
xlsheet.Cells(2,1).Value="card number";
xlsheet.Cells(2,2).Value="password";
xlsheet.Cells(2,3).Value="Billing Method";
xlsheet.Cells(2,4).Value="Value Number of Valid Days";
xlsheet.Cells(2,5).Value="amount";
xlsheet.Cells(2,6).Value="Service Item";
xlsheet.Cells(2,7).Value="issuance time";
var oTable=document.all['fors:data'];
var rowNum=oTable.rows.length;
for(i=2;i<=rowNum;i++){
for (j=1;j<=7;j++){
//html table class content is written to excel
xlsheet.Cells(i+1,j).Value=oTable.rows(i-1).cells(j-1).innerHTML;
}
}
<!-- xlsheet.Range(xls.Cells(i+4,2),xls.Cells(rowNum,4)).Merge; -->
// xlsheet.Range(xlsheet.Cells(i, 4), xlsheet.Cells(i-1, 6)).BorderAround , 4
// for(mn=1,mn<=6;mn++) . xlsheet.Range(xlsheet.Cells(1, mn), xlsheet.Cells(i1, j)).Columns.AutoFit;
xlsheet.Columns.AutoFit;
xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(rowNum+1,7)).HorizontalAlignment =-4108;//Center
xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(1,7)).VerticalAlignment =-4108;
xlsheet.Range( xlsheet.Cells(2,1), xlsheet.Cells(rowNum+1,7)).Font.Size=10;
xlsheet.Range( xlsheet.Cells(2,1), xlsheet.Cells(rowNum+1,7)).Borders(3).Weight = 2; //Set the left margin
xlsheet.Range( xlsheet.Cells(2,1), xlsheet.Cells(rowNum+1,7)).Borders(4).Weight = 2;//Set the right margin
xlsheet.Range( xlsheet.Cells(2,1), xlsheet.Cells(rowNum+1,7)).Borders(1).Weight = 2;//Set the top margin
xlsheet.Range( xlsheet.Cells(2,1), xlsheet.Cells(rowNum+1,7)).Borders(2).Weight = 2;//Set the bottom margin
xls.UserControl = true; //It is very important and cannot be omitted, otherwise there will be problems. It means that excel is left to the user to control
xls=null;
xlBook=null;
xlsheet=null;
}
</script> <link href="css/styles3.css" rel="stylesheet" type="text/css"/>
<title>ziyuanweihu</title>
</head>
<body>
<form id="fors" method="post" action="/WebModule/admins/card/showcard.faces" enctype="application/x-www-form-urlencoded">
<table id="fors:top" cellpadding="0" cellpacing="0">
<tbody>
<tr>
<td><img src="images/jiao1.gif" /></td>
<td></td>
<td><img src="images/jiao2.gif" /></td>
</tr>
</tbody>
</table>
<table cellpadding="0" cellpacing="0">
<tbody>
<tr>
<td></td>
<td><table id="fors:sort" cellpadding="0" cellpacing="0" style="valign:center">
<tbody>
<tr>
<td><input type="button" name="fors:_id7" value="generate excel file" onclick="MakeExcel()" /><input type="submit" name="fors:_id8" value="return" /></td>
</tr>
</tbody>
</table>
<table id="fors:data" cellpadding="0" cellpacing="1">
<head>
<tr>
<th scope="col"><span id="fors:data:headerText1">card number</span></th>
<th scope="col"><span id="fors:data:headerText2">Password</span></th>
<th scope="col"><span id="fors:data:headerText3">Billing method</span></th>
<th scope="col"><span id="fors:data:headerText4">Valid days</span></th>
<th scope="col">amount</th>
<th scope="col"><span id="fors:data:headerText6">Services</span></th>
<th scope="col"><span id="fors:data:headerText7">issuance time</span></th>
</tr>
</head>
<tbody>
<tr>
<td>h000010010</td>
<td>543860</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010011</td>
<td>683352</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010012</td>
<td>433215</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010013</td>
<td>393899</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010014</td>
<td>031736</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010015</td>
<td>188600</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010016</td>
<td>363407</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010017</td>
<td>175315</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010018</td>
<td>354437</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010019</td>
<td>234750</td>
<td>Counting points</td>
<td></td>
<td>2.0</td>
<td>Test Project</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
</tbody>
</table>
</td>
<td></td>
</tr>
</tbody>
</table>
<table id="fors:bottom" cellpadding="0" cellpacing="0">
<tbody>
<tr>
<td>
<img src="images/jiao3.gif"/>
</td>
<td> </td>
<td>
<img src="images/jiao4.gif"/>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="fors" value="fors" /></form>
</body>
</html>