<%@ page c %>
<h1>content</h1>
<html>
<head>
<script language="javascript" type="text/javascript">
function MakeExcel() {
var i, j, n;
try {
var xls = new ActiveXObject("Excel.Application");
}
catch(e) {
alert( "要打印該表,您必須安裝Excel電子表格軟件,同時(shí)瀏覽器須使用“ActiveX 控件”,您的瀏覽器須允許執行控件。請點(diǎn)擊【幫助】了解瀏覽器設置方法!");
return "";
}
xls.visible =true; // 設置excel為可見(jiàn)
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="發(fā)卡記錄";
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,3)).Interior.ColorIndex=5; // 設置底色為藍色
// xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Font.ColorIndex=4; // 設置字體色
// xlsheet.Rows(1). Interior .ColorIndex = 5 ;//設置底色為藍色 設置背景色 Rows(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 = "黑體" -->
xlsheet.Rows(1).Font.Name="黑體";
<!--設置列寬 xlsheet.Columns(2)=14;-->
xlsheet.Columns("A:D").ColumnWidth =18;
<!--設置顯示字符而不是數字-->
xlsheet.Columns(2).NumberFormatLocal="@";
xlsheet.Columns(7).NumberFormatLocal="@";
//設置單元格內容自動(dòng)換行 range.WrapText = true ;
//設置單元格內容水平對齊方式 range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//設置單元格內容豎直堆砌方式
//range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
//range.WrapText = true; xlsheet.Rows(3).WrapText=true 自動(dòng)換行
//設置標題欄
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 = "所屬服務(wù)項目";
xlsheet.Cells(2, 7).Value = "發(fā)卡時(shí)間";
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類(lèi)容寫(xiě)到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;//居中
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; //設置左邊距
xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(4).Weight = 2;//設置右邊距
xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(1).Weight = 2;//設置頂邊距
xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(2).Weight = 2;//設置底邊距
xls.UserControl = true; //很重要,不能省略,不然會(huì )出問(wèn)題 意思是excel交由用戶(hù)控制
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" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="left"><img src="images/jiao1.gif" alt="" /></td>
<td class="topMiddle"></td>
<td class="right"><img src="images/jiao2.gif" alt="" /></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="middleLeft"></td>
<td class="btstyle">
<table id="fors:sort" border="0" cellpadding="0" cellspacing="0" style="valign:center" width="100%">
<tbody>
<tr>
<td class="btstyle">
<input type="button" name="fors:_id7" value="生成excel文件" />
</td>
</tr>
</tbody>
</table>
<table id="fors:data" border="1" cellpadding="0" cellspacing="1" width="100%">
<thead>
<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">所屬服務(wù)項目</span></th>
<th scope="col"><span id="fors:data:headerText7">發(fā)卡時(shí)間</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>h000010010</td>
<td>543860</td>
<td>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</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>計點(diǎn)</td>
<td></td>
<td>2.0</td>
<td>測試項目</td>
<td>2006-06-23 10:14:40.843</td>
</tr>
</tbody>
</table>
</td>
<td class="middleRight"></td>
</tr>
</tbody>
</table>
<table id="fors:bottom" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="left">
<img src="images/jiao3.gif" alt=""/>
</td>
<td class="bottomMiddle"> </td>
<td class="right">
<img src="images/jiao4.gif" alt=""/>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="fors" value="fors" />
</form>
</body>
</html>
<%--
// ---------------------------------- 1 ---------------------------------- \\
<HTML>
<HEAD>
<TITLE>導出到excel</TITLE>
<META NAME="Generator" C>
<META NAME="Author" C>
<META NAME="Keywords" C>
<META NAME="Description" C>
</HEAD>
<script language="javascript">
function exportExcel(tableid) {
if(typeof(EXPORT_OBJECT)!="object") {
document.body.insertAdjacentHTML("afterBegin","<OBJECTstyle=‘display:none‘classid=‘clsid:0002E510-0000-0000-C000-000000000046‘id=‘EXPORT_OBJECT‘></Object>");
}
with(EXPORT_OBJECT) {
DataType = "HTMLData";
HTMLData =tableid.outerHTML;
try {
ActiveSheet.Export("d:\\表格.xls", 0);
alert(‘成功導出EXCEL表格!‘);
}
catch (e) {
alert(‘導出EXCEL表格失敗,請確定已安裝Excel2000(或更高版本),并且沒(méi)打開(kāi)同名xls文件‘);
}
}
}
</script>
<BODY>
<table id="tableid" border="1">
<tr>
<td>第一個(gè)單元格</td>
<td>第二個(gè)單元格</td>
<td>第三個(gè)單元格</td>
</tr>
<tr>
<td>第四個(gè)單元格</td>
<td>第五個(gè)單元格</td>
<td>第六個(gè)單元格</td>
</tr>
</table>
<input type="button" value="導出EXCEL表格" >
</BODY>
</HTML>
// ---------------------------------- 2 ---------------------------------- \\
<!-- 導出到office2000版本的word或excel中 -->
<script language="javascript">
function tableToExcel() {
window.clipboardData.setData("Text",document.all(‘theObjTable‘).outerHTML);
try {
var ExApp = new ActiveXObject("Excel.Application");
var ExWBk = ExApp.workbooks.add();
var ExWSh = ExWBk.worksheets(1);
ExApp.DisplayAlerts = false;
ExApp.visible = true;
}
catch(e) {
alert("您的電腦沒(méi)有安裝Microsoft Excel軟件!");
return false;
}
ExWBk.worksheets(1).Paste;
}
function tableToWord() {
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(theObjTable);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
}
</script>
<table id="theObjTable">
<tr>
<td>在html頁(yè)面中</td>
<td>把網(wǎng)頁(yè)中的表</td>
<td>格內容導入到</td>
<td>word中</td>
<td>也可以導入到excel</td>
</tr>
</table>
<input type="button" value="導入到excel" >
<input type="button" value="導入到word" >
// ---------------------------------- 3 ---------------------------------- \\
--%>
******************************************************************************************************
******************************************************************************************************