脚本导出datagird/gridview数据
时间:2010-12-17 来源:jasonC
var oControlRange = document.body.createControlRange();
oControlRange.add(tempTable,0);
oControlRange.select();
document.execCommand("Copy");
document.body.removeChild(tempTable);
var xls;
try
{
xls = new ActiveXObject( "Excel.Application" );
}
catch(e)
{
ShowHtmlString("提示","<div style='padding:15px;'>你的浏览器设置不正确或Excel没有安装!<br />请启用Active控件和插件.<br />可以点击以下链接查看参考设置步骤:<br /><a href='ActiveX.htm' target='_blank'>ActiveX设置说明</a></div>",330,120);
return false;
}
xls.visible = true;
var xlBook = xls.Workbooks.Add;
var xlsheet = xlBook.Worksheets(1);
xlBook.Worksheets(1).Activate;
xlsheet.Paste;
xls=null;
}
//Add by bisdev01(luqingfei)#2010-11-19 只保留文字资料,删除input,image,以及隐藏的元素
function removeHiddenElement(parentElement)
{
if (parentElement != null)
{
for(var i=parentElement.children.length-1; i >= 0; i--)
{
var cld = parentElement.children(i);
if (cld.tagName.toLowerCase() == "input"
|| cld.tagName.toLowerCase() == "img" )
{
parentElement.removeChild(cld);
continue;
}
if (cld.style.display.toLowerCase() == "none")
{
parentElement.removeChild(cld);
continue;
}
cld.style.color = "black";
if (cld.children.length > 0)
{
removeHiddenElement(cld);
}
}
}
}