EMC范承工:“五大支柱”为云计算保驾护航
2009-12-14 15:02
253 查看
下面代码是C# .net输出word和excel文件的公告函数,使用方法先建立gridview填充数据,然后用时copy如下函数到cs页面,调用方法 OutExcel(GridviewName, "File name.xls"); OutWord(GridviewName, "File name.doc");
指定gridview的 名字和文件名即可!
//输出到excel的函数,可直接copy到 cs页面
private void OutExcel(GridView dg, string name)
{
dg.Visible = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
name = "attachment;filename=" + name;
Response.AppendHeader("Content-Disposition", name);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
//输出到word的函数,可直接copy到 cs页面
private void OutWord(GridView dg, string name)
{
//string name="lessons.xls";
dg.Visible = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
name = "attachment;filename=" + name;
Response.AppendHeader("Content-Disposition", name);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-word";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
//重载VerifyRenderingInServerForm方法,调用页面必须加入否则会提示错误
public override void VerifyRenderingInServerForm(Control control)
{
}
//调用方法 OutWord(Student, "File name.doc");
protected void Button1_Click(object sender, EventArgs e)
{
OutWord(Student, "File name.doc");
}
//调用方法 OutExcel(Student, "File name.xls");
protected void Button2_Click(object sender, EventArgs e)
{
OutExcel(Student, "File name.xls");
}
通过以上方式输出的word、Excel是没有格式的
本文出自 “www.faako.com” 博客,请务必保留此出处http://leyton.blog.51cto.com/892183/370299
指定gridview的 名字和文件名即可!
//输出到excel的函数,可直接copy到 cs页面
private void OutExcel(GridView dg, string name)
{
dg.Visible = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
name = "attachment;filename=" + name;
Response.AppendHeader("Content-Disposition", name);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
//输出到word的函数,可直接copy到 cs页面
private void OutWord(GridView dg, string name)
{
//string name="lessons.xls";
dg.Visible = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
name = "attachment;filename=" + name;
Response.AppendHeader("Content-Disposition", name);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-word";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
//重载VerifyRenderingInServerForm方法,调用页面必须加入否则会提示错误
public override void VerifyRenderingInServerForm(Control control)
{
}
//调用方法 OutWord(Student, "File name.doc");
protected void Button1_Click(object sender, EventArgs e)
{
OutWord(Student, "File name.doc");
}
//调用方法 OutExcel(Student, "File name.xls");
protected void Button2_Click(object sender, EventArgs e)
{
OutExcel(Student, "File name.xls");
}
通过以上方式输出的word、Excel是没有格式的
本文出自 “www.faako.com” 博客,请务必保留此出处http://leyton.blog.51cto.com/892183/370299
相关文章推荐
- 第三届云计算大会 - EMC全球高级副总裁范承工:当云计算遇到海量数据(转载)
- SafeNet以数据为中心的安全解决方案为“云计算”部署保驾护航
- SafeNet以数据为中心的安全解决方案为“云计算”部署保驾护航
- 软件测试保驾护航 助力银行业铺就瞬捷IT路
- 海云安为全球用户保驾护航
- 虚伪的政策意在为高房价保驾护航
- 城市交通的“最强大脑” ——“公交调度应急指挥平台”为“两会”保驾护航
- “黑客”眼中云计算的“五大漏洞”
- 云计算来袭,如果IOE(IBM, oracle, EMC)不思变革反而用私有云作救命稻草那么IOE的没落才开始
- 软件测试保驾护航 助力银行业铺就瞬捷IT路
- 农业物联网为食品安全保驾护航
- 【头条】谁在为亚洲单体容量最大的数据中心保驾护航?
- 利用DLP系统为CRM数据保驾护航
- 多国相继出台政策法规:为「自动驾驶」的「创新发展」保驾护航
- 使用let's encrypt为你的Ubuntu14+nginx网站保驾护航!
- 银华基金:用小型机的群狼战术保驾护航!
- 【专题一】IBM虚拟化与云计算高峰论坛调查:是什么影响了您虚拟化的的进程――虚拟化的五大忧虑
- 天瑞地安电子锁APP应用 为安全家居保驾护航
- 沪深股市22日冲高回落 蓝筹为股指保驾护航
- Doctor ANS为服务器健康保驾护航!