การคัดลอกรหัสมีดังนี้:
<html>
<head>
<script language = "javascript" type = "text/javascript">
ฟังก์ชั่น makeexcel () {
var i, j;
พยายาม {
var xls = new ActiveXObject ("excel.application");
-
จับ (e) {
การแจ้งเตือน ("ในการพิมพ์ตารางนี้คุณต้องติดตั้งซอฟต์แวร์สเปรดชีต Excel และเบราว์เซอร์จะต้องใช้" ActiveX Controls "และเบราว์เซอร์ของคุณจะต้องอนุญาตให้ดำเนินการควบคุมได้โปรดคลิก [Help] เพื่อทำความเข้าใจวิธีการตั้งค่าเบราว์เซอร์!");
กลับ "";
-
xls.visible = true; // ตั้งค่า Excel ให้มองเห็นได้
var xlbook = xls.workbooks.add;
var xlsheet = xlbook.worksheets (1);
<!-ผสาน->
xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,7)). mergecells = true;
XLSheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,7)). value = "บันทึกการออกบัตร";
// xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,6)). interior.colorindex = 5; // ตั้งค่าสีพื้นหลังเป็นสีน้ำเงิน
// xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,6)). font.colorindex = 4; // ตั้งค่าสีตัวอักษร
// xlsheet.rows (1) Interior .ColorIndex = 5; // ตั้งค่าสีพื้นหลังเป็นสีน้ำเงิน ตั้งค่าแถวสีพื้นหลัง (1) .Font.ColorIndex = 4
<!-ตั้งค่าความสูงของเส้น->
xlsheet.rows (1) .rowheight = 25;
<!-ตั้งค่าแบบอักษร ws.range (ws.cells (i0+1, j0), ws.cells (i0+1, j1)). font.size = 13->
xlsheet.rows (1) .font.size = 14;
<!-ตั้งค่าตัวอักษรตั้งค่าตัวอักษรของพื้นที่ที่เลือก xlsheet.Range (xlsheet.cells (i0, j0), ws.cells (i0, j0)). font.name = "bold"->
xlsheet.rows (1) .font.name = "boldbody";
<!-ตั้งค่าความกว้างของคอลัมน์ xlsheet.columns (2) = 14;->
xlsheet.columns ("A: D"). columnWidth = 18;
<!-ตั้งค่าอักขระแสดงผลแทนตัวเลข->
xlsheet.columns (2) .numberFormatLocal = "@";
xlsheet.columns (7) .numberFormatLocal = "@";
// ตั้งค่าเนื้อหาเซลล์ให้ห่อช่วงบรรทัดโดยอัตโนมัติ wwraptext = true;
// ตั้งค่าการจัดตำแหน่งแนวนอนของช่วงเนื้อหาของเซลล์ horizontalalignment = excel.xlhalig.xlhaligcenter; // ตั้งวิธีการจัดซ้อนแนวตั้งของเนื้อหาเซลล์เนื้อหาของเซลล์
//range.verticalalignment=excel.xlvalign.xlvaligncenter
//range.wraptext = true; xlsheet.rows (3) .wraptext = การห่ออัตโนมัติที่แท้จริง
// ตั้งค่าแถบชื่อเรื่อง
xlsheet.cells (2,1) .Value = "หมายเลขบัตร";
xlsheet.cells (2,2) .Value = "รหัสผ่าน";
xlsheet.cells (2,3) .Value = "วิธีการเรียกเก็บเงิน";
xlsheet.cells (2,4) .Value = "จำนวนค่าของวันที่ถูกต้อง";
xlsheet.cells (2,5) .Value = "จำนวน";
xlsheet.cells (2,6) .Value = "รายการบริการ";
xlsheet.cells (2,7) .Value = "เวลาออก";
var otable = document.all ['fors: data'];
var rownum = otable.rows.length;
สำหรับ (i = 2; i <= rownum; i ++) {
สำหรับ (j = 1; j <= 7; j ++) {
// เนื้อหาคลาสตาราง html ถูกเขียนไปยัง 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
// สำหรับ (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)). เส้นขอบ (3) .weight = 2; // ตั้งค่าขอบซ้าย
XLSheet.Range (xlsheet.cells (2,1), xlsheet.cells (Rownum+1,7)). เส้นขอบ (4) .weight = 2; // ตั้งค่าขอบด้านขวา
XLSheet.Range (xlsheet.cells (2,1), xlsheet.cells (Rownum+1,7)). เส้นขอบ (1) .weight = 2; // ตั้งค่าขอบบนสุด
XLSheet.Range (xlsheet.cells (2,1), xlsheet.cells (rownum+1,7)). เส้นขอบ (2) .weight = 2; // ตั้งค่าขอบล่าง
xls.usercontrol = true; // มันสำคัญมากและไม่สามารถละเว้นได้มิฉะนั้นจะมีปัญหา หมายความว่า Excel ถูกทิ้งไว้ให้ผู้ใช้ควบคุม
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 = "แอปพลิเคชัน/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> <อินพุต type = "button" name = "fors: _id7" value = "สร้างไฟล์ excel" onclick = "makeexcel ()" /> <อินพุต type = "ส่ง" 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"> หมายเลขบัตร </span> </th>
<th scope = "col"> <span id = "fors: data: headertext2"> รหัสผ่าน </span> </th>
<th scope = "col"> <span id = "fors: data: headertext3"> วิธีการเรียกเก็บเงิน </span> </th>
<th scope = "col"> <span id = "fors: data: headertext4"> วันที่ถูกต้อง </span> </th>
<th scope = "col"> จำนวน </th>
<th scope = "col"> <span id = "fors: data: headertext6"> บริการ </span> </th>
<th scope = "col"> <span id = "fors: data: headertext7"> เวลาออก </span> </th>
</tr>
</head>
<tbody>
<tr>
<Td> H000010010 </td>
<td> 543860 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010011 </td>
<TD> 683352 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010012 </td>
<TD> 433215 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010013 </td>
<td> 393899 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010014 </td>
<td> 031736 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010015 </td>
<TD> 188600 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010016 </td>
<TD> 363407 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010017 </td>
<TD> 175315 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010018 </td>
<TD> 354437 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </td>
<TD> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010019 </td>
<TD> 234750 </td>
<td> การนับคะแนน </td>
<td> </td>
<td> 2.0 </td>
<td> โครงการทดสอบ </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>
<อินพุต type = "hidden" name = "fors" value = "fors" /> </form>
</body>
</html>