(原创)easyui基于web的打印实现

<%@ page language="java"pageEncoding="UTF-8"%>

<object id="WebBrowser"classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2"width="0" height="0">

object>

<script language="javascript"type="text/javascript">

var tableString = "";

function doPrint()

{

      tableString += "window.print();+"cript>";

      // tableString.insertAdjacentHTML("beforeBegin","window.print();")

      document.open('','','height=500,width=611,scrollbars=yes,status =yes');

     document.write(tableString);

      document.close();

}

 

// strPrintName 打印任务名

// printDatagrid 要打印的datagrid

function CreateFormPage(strPrintName, printDatagrid) {

    var frozenColumns = printDatagrid.datagrid("options").frozenColumns;  // 得到frozenColumns对象

    var columns = printDatagrid.datagrid("options").columns;    // 得到columns对象

 

    // 载入title

    tableString = tableString + "\n";

    if(frozenColumns != undefined && frozenColumns != '') {

       for(var i = 0;i

           if(frozenColumns[0][i].hidden != true) {

              tableString = tableString + "\n" + frozenColumns[0][i].title + "";

           }

       }

    }

    if(columns != undefined && columns != '') {

       for(var i = 0;i

           if(columns[0][i].hidden != true) {

              tableString = tableString + "\n" + columns[0][i].title + "";

           }

       }

    }

    tableString = tableString + "\n";

 

    // 载入内容

    var rows = printDatagrid.datagrid("getRows"); // 这段代码是获取当前页的所有行。

    for(var j = 0; j

       tableString = tableString + "\n";

       if(frozenColumns != undefined && frozenColumns != '') {

           for(var i = 0;i

              if(frozenColumns[0][i].hidden != true) {

                  tableString = tableString + "\n" + rows[j][frozenColumns[0][i].field] + "";

              }

           }

       }

       if(columns != undefined && columns != '') {

           for(var i = 0;i

              if(columns[0][i].hidden != true) {

                  tableString = tableString + "\n" + rows[j][columns[0][i].field] + "";

              }

           }

       }

       tableString = tableString + "\n";

    }

    tableString = tableString + "\n";

    doPrint();

}

 

script>

 

 

 

 

使用方法: jsp页面中

<jsp:include page="../../../Lodop/print2.jsp">jsp:include>

Js页面中

function prn_preview() {

    CreateFormPage("核销账款明细", stockDocumentDatagrid);

};

第一个参数是单据名称; 第二个是要打印的datagrid对象

 

作者 : 张振斌     时间 :2013-3-18   QQ:739934487

你可能感兴趣的:(easyui)