下面是打印网页部分内容的代码,但是……,求解!

jisuanjizhuan 2012-09-10 09:08:55
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Securities.aspx.cs" Inherits="Maticsoft.Web.Securities" %>

<!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 runat="server">
<title>查看审核密码</title>
<link rel="Stylesheet" href="css/StyleSheet1.css" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
不打印
<asp:Panel ID="Panel1" runat="server">
打印
</asp:Panel>
<asp:ImageButton ID="ImageButton1" runat="server" onclick="ImageButton1_Click" />
</form>
</body>
</html>

后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Maticsoft.Web
{
public partial class Securities : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
OutPutDocumnet("word");
}
public void OutPutDocumnet(string type)
{
//定义文档类型、字符编码
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
string filename = DateTime.Now.ToString() + "优惠劵.doc";
string fname = HttpUtility.UrlEncode(filename);
//attachment 参数表示作为附件下载,可以改成 online在线打开
//filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc    .xls    .txt   .htm
if (type == "word")
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fname);
else if (type == "excel")
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fname);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
if (type == "word")
Response.ContentType = "application/ms-word";
else if (type == "excel")
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;

// 定义一个输入流
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

this.Panel1.RenderControl(oHtmlTextWriter);
//this 表示输出本页,你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
Response.Write(oStringWriter.ToString());
Response.End();
}
}
}

XP系统下运行的结果:打印
win7系统下运行的结果:
<div id="Panel1">


打印

</div>

貌似不太兼容win7,如何使这段代码兼容win7?
...全文
189 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jisuanjizhuan 2012-09-10
  • 打赏
  • 举报
回复
是将指定内容导入word中,并下载!
jisuanjizhuan 2012-09-10
  • 打赏
  • 举报
回复
是下载,口误!!

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧