您的位置:首页 > 其它

如何将网页内容导出到EXCEL表中……

2007-10-18 16:58 387 查看
<html>
<body>
<BR>
<table id = "PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor = "#61FF13">
<TR style="text-align : center;">
<TD>单元格A</TD>
<TD>单元格A</TD>
</TR>
<TR>
<TD colSpan=2 style="text-align : center;"><font color="BLUE" face="Verdana">单元格合并行A</FONT></TD>
</TR>
</TABLE>
<br>
<input type="button" onclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel">
<SCRIPT LANGUAGE="javascript">
//指定页面区域内容导入Excel
function AllAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel=document.body.createTextRange();
//PrintA是table的id
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}
</SCRIPT>

<body>
</html>

随便将上面的文件保存成.htm文件,就可以看到效果啦,关键是红色字体……它实现了导出功能,当然,如果要导入到word就应该下面:
<script language="javascript">
function OpenWord(){
Layer1.style.border=0
ExcelSheet = new ActiveXObject('word.Application');
ExcelSheet.Application.Visible = true;
var mydoc=ExcelSheet.Documents.Add('',0,1);
myRange =mydoc.Range(0,1)
var sel=Layer1.document.body.createTextRange()
sel.select()
Layer1.document.execCommand('Copy')
sel.moveEnd('character')
myRange.Paste();
location.reload()
ExcelSheet.ActiveWindow.ActivePane.View.Type=9
}
</script>


如果要调用window的打印功能,如下:

<script language="javascript">
function print()
{
window.print();
}
</script>
文章引用自:

<SCRIPT LANGUAGE="JavaScript">
<!--
function FunSave(strContent) {
   var strOut=getStyle()+strContent;

   var winSave = window.open();
   winSave.document.open ("text/html","gb2312");
   winSave.document.write (strOut);
   winSave.document.execCommand ("SaveAs",true,"yourExecl.xls");
   winSave.close();
}
function getStyle(){
var Style='<style>TB{BACKGROUND-COLOR: black;FONT-SIZE: 12px;LINE-HEIGHT: 16px;TEXT-DECORATION: none;} td{mso-number-format:"/@";BACKGROUND-COLOR:white} td.top{BACKGROUND-COLOR: #4F93DC;COLOR: #ffffff;FONT-SIZE: 12px; LINE-HEIGHT: 16px; TEXT-DECORATION: none;}</style>';
return Style;
}
//-->
</SCRIPT>

然后在网页里插入下面按扭:
<input type="button" name="Submit2" onclick="FunSave(outStudent.outerHTML)" value="导出到EXCEL">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: