web 打印 该用什么控件

winnerfathot 2011-03-31 10:58:19
用户也需要通过excel 导入数据。然后 自定义 表格样式 打印。
...全文
92 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
porschev 2011-03-31
  • 打赏
  • 举报
回复

百度一下呗。。。

web免费打印控件MS不少。。。
http://shenlan.blog.51cto.com/55742/365339
子夜__ 2011-03-31
  • 打赏
  • 举报
回复
/// <summary>
/// 将Web控件导出
/// </summary>
/// <param name="source">控件实例</param>
/// <param name="type">类型:Excel或Word</param>
public void ExpertControl(System.Web.UI.Control source, DocumentType type)
{
//设置Http的头信息,编码格式
if (type == DocumentType.Excel)
{
//Excel
Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
Response.ContentType = "application/ms-excel";
}
else if (type == DocumentType.Word)
{
//Word
Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
Response.ContentType = "application/ms-word";
}
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;

//关闭控件的视图状态
source.Page.EnableViewState =false;

//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter);

//输出
Response.Write(writer.ToString());
Response.End();
}

//文档类型
public enum DocumentType
{
Word,
Excel
}


/// <summary>
/// 导出Excel
/// </summary>
/// <param name="ds">Dataset</param>
/// <param name="FileName">文件名,包括后缀。如:xxx.xls</param>
public void CreateExcel(DataSet ds, string FileName)
{
HttpResponse resp;
resp = Page.Response;
FileName = Page.Server.UrlEncode(FileName); //文件名编码,否则出现乱码
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
string colHeaders = "", ls_item = "";
//定义表对象与行对象,同时用DataSet对其值进行初始化
DataTable dt = ds.Tables[0];

DataRow[] myRow = dt.Select();//可以类似dt.Select("id>10")之形式达到数据筛选目的
int i = 0;

int cl = dt.Columns.Count;
//取得数据表各列标题,各标题之间以t分割,最后一个列标题后加回车符
colHeaders = "姓名\t性别\n";
resp.Write(colHeaders);
//向HTTP输出流中写入取得的数据信息
//逐行处理数据
foreach (DataRow row in myRow)
{
//当前行数据写入HTTP输出流,并且置空ls_item以便下行数据
ls_item += row["Uname"].ToString() + "\t" + row["Usex"].ToString() + "\n";
resp.Write(ls_item);
ls_item = "";
}
resp.End();
}

winnerfathot 2011-03-31
  • 打赏
  • 举报
回复
我想实现的是 : word 里面的 信封 功能。。。不知道该怎么实现

62,046

社区成员

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

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

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

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