我做了一个 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();求答案~~~
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();求答案~~~
解决方案 »
- 奇怪的问题。为什么服务器ie9下面就不引用css样式呢? 有人遇见过么?
- vs2005 asp.net CheckBox 三态控件
- FCKEditor如何搞普通的插入图片(不带上传的)
- 请高手指教,为什么我不能对我画出来的东东进行精确定位??
- Access中如何模拟SqlServer中的DATEADD函数?
- 请问有没有一个语句可以在指定窗口中打开网页的?
- 有关javascript的小问题
- 请教问题,如何在ASP.NET(C#)中调用VBSCRIPT写的方法?
- 水晶报表打印问题
- 怎么用CSS或是其他方法让它对齐:
- web页面内的文字和图片都会随窗口大小而缩放?新手求问~
- 帮忙测试下 聊天室程序 会不会 崩溃
不能在导出excel 的时候,控制好打印机设置吗
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 //下边距
}