js改變列印設定 和自動改變字型大小不伸縮td大小
stringBuffer.append("<script type=/"text/javascript/">");
stringBuffer.append("var hkey_root,hkey_path,hkey_key;");
stringBuffer.append("hkey_root=/"HKEY_CURRENT_USER/";");
stringBuffer.append("hkey_path=/"////Software////Microsoft////Internet Explorer////PageSetup/////";");
//配置網頁列印的頁首頁尾為空
stringBuffer.append("function pagesetup_null(){ " +
"try{ "+
" var RegWsh = new ActiveXObject(/"WScript.Shell/"); "+
" hkey_key=/"header/"; "+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,/"/"); "+
" hkey_key=/"footer/"; "+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,/"/"); "+
" hkey_key=/"margin_left/";"+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"+leftWidthBJ+"); "+
" hkey_key=/"margin_top/";"+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"+topHeightBJ+"); "+
" hkey_key=/"margin_right/";"+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"+rightWidthBJ+");"+
" hkey_key=/"margin_bottom/";"+
" RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"+bottomHeightBJ+");"+
" window.print();"+
"}catch(e){"+
" alert(/"請手動設定啟用IE的ActiveX控制元件功能,完成列印!(/"+e.message+/")/");return;"+
//開啟你的ie瀏覽器internet選項—— 安全—— 自定義級別—— 把對沒有標記為安全的activex控制元件進行初始化和指令碼執行 設定為啟用。
" } ");
stringBuffer.append("}");
//配置網頁列印的頁首頁尾為預設值
/*stringBuffer.append("function pagesetup_default(){ ");
stringBuffer.append("try{ "+
" var RegWsh = new ActiveXObject(/"WScript.Shell/"); "+
" hkey_key=/"header/"; "+
//RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b頁碼,&p/&P") ;
"RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,/"/") ;"+
"hkey_key=/"footer/"; "+
//RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d");
"RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,/"/"); "+
"}catch(e){} ");
stringBuffer.append("} ");*/
stringBuffer.append("function changSize(){"+
"for(var i=1;i<="+list.size()+";i++){"+
" var divObj=document.getElementById(/"divObj_/"+i);"+
"if(divObj!=null){"+
" if(divObj.style.fontSize!=/"/"){"+
" var fontw=parseInt(divObj.style.fontSize); "+//初始的字型大小
" } "+
" var fonth=fontw+2;"+//初始字型高度
" var width=divObj.offsetWidth;"+//DIV的寬度
" var height=divObj.offsetHeight;"+//div的高度
" var lenstr=divObj.innerText.length;"+//DIV裡文字長度
" fonts=fontw*fonth*lenstr;"+//字體面積
" divs=width*height;"+//DIV面積
" if(fonts>divs)"+
" {"+
" var rfont;"+//重設字型大小為rfont
//" rfont=Math.round((Math.sqrt(4*lenstr*divs-4*lenstr*lenstr)-2*lenstr)/(2*lenstr))-0.1;"+
" rfont=Math.round((Math.sqrt(4*lenstr*divs-4*lenstr*lenstr)-2*lenstr)/(2*lenstr));"+
" divObj.style.fontSize=rfont+/"px/";"+
" }"+
" }"+
" }"+
"}");
stringBuffer.append("window.onload=function(){ "+
"changSize();"+
"pagesetup_null();"+
//" document.all.wb.ExecWB(7,1);"+
//" window.print();"+
" }");
stringBuffer.append("</script>");