lodop打印控件学习网站,http://www.lodop.net/demo.html
aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderView_From.aspx.cs" Inherits="MouldERP.ChiHZhong.OrderView_From" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>无标题页</title> <script src="js/LodopFuncs.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> var LODOP; //声明为全局变量 var iRadioValue=1; function OutToFile(){ var LODOP=getLodop(); LODOP.PRINT_INIT(""); LODOP.ADD_PRINT_TABLE(5,5,"99%","100%",document.getElementById("div1").innerHTML); //LODOP.SET_SAVE_MODE("QUICK_SAVE",true);//快速生成(无表格样式,数据量较大时或许用到) LODOP.SAVE_TO_FILE("新文件名.xls"); }; function PreviewMytable(){ LODOP=getLodop(); LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_预览打印表格"); LODOP.ADD_PRINT_HTM(10,10,"100%","100%",document.getElementById("div1").innerHTML); LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",iRadioValue); LODOP.PREVIEW(); }; </script> </head> <body> <form id="form1" runat="server"> <div id="div1" runat="server" > <%-- <div style="font-size:20px; text-align:center; font-weight:bold;" >充值统计报表</div> <div style="float:left; padding-left:50px;">制表单位:</div><div style="float:right; padding-right:50px; " >制表时间:</div> <br /> <table border="1" id="tableall" runat="server" style="border-collapse:collapse;border:solid 1px; width:100%" bordercolor="#000000"> <tr> <td>单号</td> <td>日期</td> <td>日期</td> <td>日期</td> </tr> <tr> <td>111</td> <td>222</td> <td>222</td> <td>222</td> </tr> </table>--%> </div> <br /> <div style="text-align:center"> <input type="button" value="打印" οnclick="PreviewMytable()" style="display:none;" /> <input type="button" value="导出" οnclick="OutToFile()" /> </div> </form> </body> </html> aspx.cs using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace MouldERP.ChiHZhong { public partial class OrderView_From : System.Web.UI.Page { MouldDBUtility.BaseClass bc = new MouldDBUtility.BaseClass(); public string tHtml = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["keys"] != null) { string[] keys = Request.QueryString["keys"].ToString().Split('|'); int count = 1; //tHtml += " <div style=\"font-size:18px; text-align:center; font-weight:bold;\" >报价单</div> "; //tHtml += " <div style=\"float:left; padding-left:40px;\">客户名称:" + dt.Rows[0]["cust_no"].ToString() + "</div><div style=\"float:left; padding-left:40px;\">报价人:" + dt.Rows[0]["quo_uname"].ToString() + "</div><div style=\"float:right; padding-right:40px; \" >报价日期:" + dt.Rows[0]["quo_date"].ToString().Substring(0,9) + "</div>"; //tHtml += " <br />"; tHtml += " <table border='1' id='tableall' style='font-size:10px; border-collapse:collapse;border:solid 1px; width:100%' bordercolor='#000000'>"; tHtml += " <tr style=\"font-size:20px; text-align:center; font-weight:bold;\" > "; tHtml += " <td colspan=\"18\">客户订单</td>"; tHtml += " </tr> "; tHtml += " <tr style=\"font-size:20px; text-align:center; font-weight:bold;\" > "; tHtml += " <td colspan=\"18\"></td>"; tHtml += " </tr> "; for (int k = 0; k < keys.Length - 1; k++) { string sql = " select * from ChiH_Order where order_id='" + keys[k] + "' "; DataTable dt = bc.ReadTable(sql); if (dt.Rows.Count > 0) { string sql2 = " select * from ChiH_Order_Matter where order_nom='" + dt.Rows[0]["order_no"] + "' "; DataTable dt2 = bc.ReadTable(sql2); if (dt2.Rows.Count > 0) { tHtml += " <tr style=\"font-size:15px; text-align:center; font-weight:bold;\" > "; tHtml += " <td colspan=\"4\">客户名称:" + dt.Rows[0]["cust_no"].ToString() + "</td>"; tHtml += " <td colspan=\"4\">制单人:" + dt.Rows[0]["touching_uname"].ToString() + "</td>"; tHtml += " <td colspan=\"5\">制单日期:" + dt.Rows[0]["touching_date"].ToString().Substring(0, 9) + "</td>"; tHtml += " <td colspan=\"5\">订单单号:" + dt.Rows[0]["order_no"].ToString() + "</td>"; tHtml += " </tr> "; //标题列和数据列 tHtml += " <tr style=\"font-size:15px; text-align:center; font-weight:bold;\" > "; tHtml += " <td>序号</td>"; tHtml += " <td>内部型号</td>"; tHtml += " <td>型号</td>"; tHtml += " <td>供应商</td>"; tHtml += " <td>来价</td>"; tHtml += " <td>售价</td>"; tHtml += " <td>下单日期</td>"; tHtml += " <td>交货日期</td>"; tHtml += " <td>颜色</td>"; tHtml += " <td>染厂染费</td>"; tHtml += " <td>染费</td>"; tHtml += " <td>订单数</td>"; tHtml += " <td>送货数</td>"; tHtml += " <td>色号</td>"; tHtml += " <td>色卡</td>"; tHtml += " <td>大货样</td>"; tHtml += " <td>单号/款号</td>"; tHtml += " <td>备注</td>"; tHtml += " </tr> "; for (int i = 0; i < dt2.Rows.Count; i++) { tHtml += " <tr style=\"font-size:10px; text-align:center;\"> "; tHtml += " <td>" + count + "</td>"; tHtml += " <td>" + dt2.Rows[i]["inside_model"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["model"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["sup_no"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["to_price"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["go_price"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["below_date"].ToString().Substring(0, 9) + "</td>"; tHtml += " <td>" + dt2.Rows[i]["deliv_date"].ToString().Substring(0, 9) + "</td>"; tHtml += " <td>" + dt2.Rows[i]["color"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["dyefactory_money"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["dye_money"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["order_num"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["deliv_num"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["color_no"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["color_card"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["large_sample"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["or_style"].ToString() + "</td>"; tHtml += " <td>" + dt2.Rows[i]["om_remark"].ToString() + "</td>"; tHtml += " </tr> "; count = count + 1; } //tHtml += " <tr style=\"font-size:20px; text-align:center; font-weight:bold; margin-top:20px;\" > "; //tHtml += " <td colspan=\"18\"></td>"; //tHtml += " </tr> "; //tHtml += " <br />"; //tHtml += " <br />"; } } } tHtml += " </table> "; this.div1.InnerHtml = tHtml; } } } } } 主页面 按钮调用JS 方法 ;checkboxx 是多选按钮name, 记录table的ID //导出execl function MyPreview(){ var temp=document.getElementsByName('checkboxx'); var keys = ""; for(var i=0;i<temp.length;i++){ if(temp[i].checked==true){ keys = keys+temp[i].value+"|"; } } if(keys!="") { wname = window.showModalDialog('OrderView_From.aspx?keys=' + keys, '', 'dialogWidth:1100px;DialogHeight=550px;status:no;help:no;resizable:no;'); } else { alert("请选择!"); } };