如何将网页内容导出到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">
<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">
相关文章推荐
- 如何将MSHFlexGrid控件中的内容导出为Excel
- JS 导出网页中Table内容到excel
- 如何通过jsoup网络爬虫工具爬取网页数据,并通过jxl工具导出到excel
- 如何将网页表格内容导入excel
- 网页内容使用JS导出为excel
- 网页内容导出word/excel的js代码
- java如何将网页表格导出为excel
- 如何将网页表格内容导入excel
- 如何把DataGrid内容导出到Excel
- vb6如何将MSHFlexGrid控件中的内容导出为Excel
- PHP 导出网页表格如何对<td>标签中的内容设置属性
- 网页内容导出word/excel的js代码
- JS 导出网页中Table内容到excel
- 问题:如何将数据库内容导出到EXCEL
- java 如何获取网页的动态内容,并解析网页内容
- 数据库中数据如何导出生成Excel?
- GridView如何将分页数据全部导出为EXCEL
- [datatables -- 学习02]: datatables 导出 CSV和excel 文件,甚至copy内容
- SEO内容优化,如何降低网页跳出率?
- 如何在VB6中导出EXCEL、FOXPRO格式的表