实现excel在线打印
生活随笔
收集整理的這篇文章主要介紹了
实现excel在线打印
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
? ?這個功能和上一篇實現(xiàn)pdf內(nèi)容中前面都差不多,讓我們直接上代碼
? body內(nèi)按鈕:
<div id='exclepdf' class="buttoncss" onclick="printout()"><img src="...."><span>在線打印</span> </div>?css樣式設(shè)計:
.buttoncss{height:35px;width:100px;text-align:center;margin:10px 0px 0px 15px;border:1px solid;float:right;margin-bottom:15px; } #excelpdf:hover {cursor:pointer; } .buttoncss img{width:25px;padding-top:5px;display:inline-block; } .buttoncss span{display:inline-block;padding-left:5px;vertical-align:super; }引入工具人js文件:
<script src="jquery-3.4.1.js"><script> <script src="jspdf.debug.js"><script> <script src="html2canvas.min.js"><script>重點來咯,關(guān)于這一在線打印目前我找到四種方法可以實現(xiàn)這一功能
開始第一個:
//整個頁面直接打印 function printout(){var newWindow;//打開一個新的窗口newWindow = window.open();//是新窗口獲得焦點newWindow.focus();//保存寫入內(nèi)容var newContent = "<html> <head> <meta charset='utf-8'/><title>打印</title> </head><body>"newContent += document.getElementById("showPC").outerHTML;newContent += "</body></html>"//將html代碼寫入新窗口中newWindow.documment.write(newContent);newWindow.print();//close layout streamnewWindow.document.close();//關(guān)閉打開的臨時窗口newWindow.close();return false; }第二個吖:
function printout(){if(!!window.activexobject || "activexobject" in window){remove_ie_header_and_footer();}window.print(); }; funtion remove_ie_header_and_footer();{var hkey_root,hkey_path,hkey_key;hkey_path = "hkey_current_user\\software//microsoft\\internet explorer \\pagesetup\\";try{var regwsh = new activexobject("wscript.shell");regwsh.regwrite(hkey_path + "header","");regwsh.regwrite(hkey_path + "footer","");}catch(e){} }第三個屬于直接讓頁面打印簡單方便,如不顏色,可直接用這個方法去實現(xiàn)excel打印:
funtion printout(){window.print(); }第四個,同樣也是最后一個,看到這個可能就沒啦,還不在上面挑一個再走?
function printout(printout){var headhtml = "<html><head><title></title></head><body>";var foothtml = "<body/>";//獲取div中的html內(nèi)容var newhtml = document.all.item(ShowPc).innerHTML;//獲取div中的html內(nèi)容var oldhtml = $("#" + ShowPc).html();var oldhtml = document.body.innerHTML;document.body.innerHTML = headhtml + newhtml + foothtml;window.print();document.body.innerHTML = oldhtml;return false; }總結(jié)
以上是生活随笔為你收集整理的实现excel在线打印的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js上传图片
- 下一篇: Top 10 Project Manag