首页 > Windows开发 > 详细

window.print()分页打印

时间:2021-02-27 10:41:40      阅读:214      评论:0      收藏:0      [点我收藏+]
  createPrintPage(data) {
            let printStr = ‘<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style>th,td{padding:2px 10px;font-size:14px} .next-table{margin:25px 0 0}</style></head><body style="padding:15px">‘,
                content = `<table border="1" style="border-collapse: collapse;width:100%"><tr><td>操作时间</td><td>查询</td><td>操作用户</td><td>备注</td></tr>`

            data.forEach((item, i) => {
                content += `<tr>
                    <td>${parseTime(item.exec_time, ‘{y}-{m}-{d} {h}:{i}:{s}‘)}</td>
                    <td>${item.exec_type}</td>
                    <td>${item.exec_user}</td>
                    <td>${item.remark}</td>
                </tr>`

                // 每页40条数据
                if (i > 0 && i % 40 === 0) {
                    content += ‘</table>‘
                    content += ‘<div style="page-break-after:always"></div>‘  // 分页
                    content += `<table class="next-table" border="1" style="border-collapse: collapse;width:100%"><tr><td>操作时间</td><td>查询</td><td>操作用户</td><td>备注</td></tr>`
                }
            })

            printStr = printStr + content + ‘</table></body></html>‘

            let printWindow = window.open("Print.html", "print")

            printWindow.document.write(printStr)
            printWindow.document.close()                   
            printWindow.print()
        }

资料

JS 使用 window对象的print方法实现分页打印

window.print()分页打印

原文:https://www.cnblogs.com/Grani/p/14454774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!