我做了一个 excel 导出 是用 Response.Write(sbHtml.ToString());  的方式画好页面导出,怎么控制打印机上的参数,比如 纵横向,纸张为A3,页眉页脚,上下左右边距。
 StringBuilder sbHtml = new StringBuilder();
sbHtml.Append("<table>");
sbHtml.Append("<tr>");
sbHtml.Append("<td>"+A.text.trim()+"<td>");
sbHtml.Append("</tr>");
sbHtml.Append(" </table>");
 Response.Clear();
 Response.ContentType = "application nd.ms-excel";
  Response.Charset = "gb2312";
 Page.EnableViewState = false;
 Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("XXXX") + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
  Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");//设置输出流为简体中文
 Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\"><title>   </title></head><body><center>");
 Response.Write(sbHtml.ToString());
  Response.Write("</center></body></html>");
  Response.End();求答案~~~

解决方案 »

  1.   


    不能在导出excel 的时候,控制好打印机设置吗
      

  2.   

    功能实现执行逻辑:
    1.设置打印机
    2.处理欲打印文档格式
    3.激活打印机打印需要ScriptX.cab控件
    下载地址http://www.meadroid.com/scriptx/index.asp
    关键代码如下:
    <object id="factory" style="display:none"
     classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
     codebase="/smsx.cab#Version=6,3,435,20">
    </object>
    JS代码如下
    function   SetPrintSettings()   {     
          //   --   advanced   features     
          factory.printing.SetMarginMeasure(2)   //   measure   margins   in   inches     
          factory.SetPageRange(false,   1,   3)   //   need   pages   from   1   to   3     
          factory.printing.printer   =   "HP   DeskJet   870C"  //打印机选择   
          factory.printing.copies   =   2                     //打印份数
          factory.printing.collate   =   true     
          factory.printing.paperSize   =   "A4"     //纸张设置
          factory.printing.paperSource   =   "Manual   feed"     
              
          //   --   basic   features     
          factory.printing.header   =   "This   is   MeadCo"     //页眉设置
          factory.printing.footer   =   "Advanced   Printing   by   ScriptX"     //页脚设置
          factory.printing.portrait   =   false     
          factory.printing.leftMargin   =   1.0     //左边距
          factory.printing.topMargin   =   1.0     //上边距
          factory.printing.rightMargin   =   1.0     //右边距
          factory.printing.bottomMargin   =   1.0     //下边距
          }