如何将网页内容导出到EXCEL表中……
来源:互联网 发布:欧特克软件认证 编辑:程序博客网 时间:2024/05/18 12:01
<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>
<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>
</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>
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">
<!--
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">
- 如何将网页内容导出到EXCEL表中……
- 如何将 Oracle 数据导出到 Excel表中 --转载
- 问题:如何将数据库内容导出到EXCEL
- 将tableview中显示的内容导出到EXCEL中
- JS 导出网页中Table内容到excel
- JS 导出网页中Table内容到excel
- 将网页内容导出到word文档中
- 将gridview的内容导出到excel中去
- 将gridview的内容导出到excel中去
- 将gridview的内容导出到excel中去
- 将gridview的内容导出到excel中去
- 将GridView的内容导出到Excel中(常见问题)
- 将gridview的内容导出到excel中去
- 将GridView的内容导出到Excel中
- 将GridView的内容导出到Excel中
- VB 将excel内容导出到指定文件中
- Servlet编程中,将网页数据导出到Excel
- 将数据库表导出到excel中
- JS一些鼠标事件
- 华为又死人了
- 利用Adorner制作用于图像裁切的选择框
- ps命令常用用法
- 多边形游戏算法
- 如何将网页内容导出到EXCEL表中……
- 用jfreechat.jar开发java图形统计程序!!
- 解决DevExpress控件安装问题
- The source of image UBB codes creator
- NHibernate1.2 执行多表查询
- 极差问题
- javascriipt HashTable
- Page事件顺序
- 终于有了一个可以切磋问题的空间了