|
<table id = "PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor = "#61FF13">
<TR style="text-align : center;">
<TD>單元格A</TD>
<TD>單元格A</TD>
<TD>單元格A</TD>
<TD>單元格A</TD>
</TR>
<TR>
<TD colSpan=4 style="text-align : center;"><font color="BLUE" face="Verdana">單元格合并行A</FONT></TD>
</TR>
</TABLE>
<table id = "PrintB" width="100%" border="1" cellspacing="0" cellpadding="0">
<TR style="text-align : center;">
<TD>單元格B</TD>
<TD>單元格B</TD>
<TD>單元格B</TD>
<TD>單元格B</TD>
</TR>
<TR>
<TD colSpan=4 style="text-align : center;">單元格合并行B</TD>
</TR>
</TABLE>
<br/>
<input type="button" onclick="Javascript:AllAreaWord();" value="導(dǎo)出頁面指定區(qū)域內(nèi)容到Word">
<input type="button" onclick="Javascript:AllAreaExcel();" value="導(dǎo)出頁面指定區(qū)域內(nèi)容到Excel">
<input type="button" onclick="Javascript:CellAreaExcel();" value="導(dǎo)出表單單元格內(nèi)容到Excel">
<SCRIPT LANGUAGE="Javascript">
//指定頁面區(qū)域內(nèi)容導(dǎo)入Excel
function AllAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel=document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}
//指定頁面區(qū)域“單元格”內(nèi)容導(dǎo)入Excel
function CellAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = PrintA.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = PrintA.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = PrintA.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
//指定頁面區(qū)域內(nèi)容導(dǎo)入Word
function AllAreaWord()
{
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(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
}
</SCRIPT>
JavaScript技術(shù):Javascript客戶端將指定區(qū)域?qū)С龅絎ord、Excel的代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。