﻿var pringccc="<OBJECT classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height='0' id='WebBrowser' width='0'></OBJECT>";

//页面设置
function setPrint()
{	printvvv=document.body.innerHTML;
	document.body.innerHTML=document.body.innerHTML+pringccc;
	document.all.WebBrowser.ExecWB(8,1);//页面设置
	document.body.innerHTML=printvvv;
}

//打印的内容
//function getPrintHtml()
//{
//return document.getElementById("dd").innerHTML+pringccc;
//}

//(打印)
function PrintWeb(obj)
{
	OpenWindow=window.open("", "Print","height=1, width=1, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no"); 
	//写成一行 
	if(OpenWindow) {
		OpenWindow.document.open();
		//aa="<html><title>打印</title><LINK href='../images/css.css' type='text/css' rel='stylesheet'><body onload=\"eval('tables=document.getElementsByTagName(\\\'table\\\');for(i=0;i<tables.length;i++){tables[i].border=1;tables[i].cellPadding=0;tables[i].cellSpacing=0;}')\">"+getPrintHtml()+"</body></html>";
		aa = "<html><title>打印</title><!--LINK href='images/css.css' type='text/css' rel='stylesheet'--><body>" + document.getElementById(obj).innerHTML + "</body></html>";
		aa=aa.replace(" color=#ffffff"," color=#000000");aa=aa.replace(" color=#ffffff"," color=#000000");aa=aa.replace(" color=#ffffff"," color=#000000")
		aa=aa.replace(" border=0"," border=1");aa=aa.replace(" border=0"," border=1");aa=aa.replace(" border=0"," border=1")
		OpenWindow.document.write(aa);
		//OpenWindow.eval("tables=document.getElementsByTagName('table');for(i=0;i<tables.length;i++){tables[i].border=1;}");
		OpenWindow.document.close();
		OpenWindow.print();//打印
		//OpenWindow.document.execCommand('Saveas',false,'导出.xls');
		OpenWindow.close();

	}
	else {
	}
	//printvvv=document.body.innerHTML;
	//document.body.innerHTML=getPrintHtml();
	//document.all.WebBrowser.ExecWB(6,1);//打印
	//document.body.innerHTML=printvvv;
}

//打印预览
function PrintWeb2()
{
	printvvv=top.document.body.innerHTML;
	top.document.body.innerHTML=getPrintHtml();
	top.document.all.WebBrowser.ExecWB(7,1);//打印预览
	//top.document.body.innerHTML=printvvv;
	//alert(getPrintHtml())
}

//另存为
function SaveAs()
{
	printvvv=document.body.innerHTML;
	document.body.innerHTML=getPrintHtml();
	document.all.WebBrowser.ExecWB(4,1);
	document.body.innerHTML=printvvv;
}
//导出xls
function outXls()
{
	printvvv=document.body.innerHTML;
	document.body.innerHTML=getPrintHtml();
	document.execCommand('Saveas',false,'test.xls');
	document.body.innerHTML=printvvv;
}
//导出到excel 
function toExcel(tablename) 
{tablename=document.getElementById("dttttt").outerHTML;
alert(tablename)
    var mysheet=new ActiveXObject("OWC.Spreadsheet"); 
    with(mysheet) 
    {
        DataType = "HTMLData"; 
        HTMLData =tablename; 
        try
        { 
            //ActiveSheet.Cells(1,1).value="ssssssssss"; 
            //ActiveSheet.Cells(2,1).value="aaaaaaaaaaaaa"; 
            //ActiveSheet.Cells(34,1).value="导出完毕"; 
            ActiveSheet.Export("导出.xls", 0); 
            alert('导出完毕'); 
        }
        catch (e)
        { 
            alert('导出Excel表失败，请确定已安装Excel2000(或更高版本),并且没打开同名xls文件'); 
        }; 
    } 
} 


//document.write("<img src=\"..\\images\\button_P1.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"PrintWeb()\">");
//document.write("<img src=\"..\\images\\button_P2.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"PrintWeb2()\">");
//document.write("<img src=\"..\\images\\button_P3.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"setPrint()\">");
//document.write("<img src=\"button_P4.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"SaveAs()\">");
//document.write("<img src=\"button_P5.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"outXls()\">");
//document.write("<img src=\"button_P1.jpg\" width=\"57\" height=\"19\" style=\"CURSOR: hand\" onclick=\"toExcel(getPrintHtml())\">");