C#窗体应用程序怎么把dataset或者是access数据库中的数据写到excel表里面
2个回答
展开全部
using System.Text;
using System.IO;
/// <summary>
/// 以下为数据导出代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton5_Click(object sender, EventArgs e)
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.ClearContent();//清除缓存区内容
Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.AppendHeader("content-disposition", "attachment; filename=MyExcelFile.xls;
Response.ContentType = "myexcel/excel";//设置输出流的类型
StringWriter sw = new StringWriter();//写入流
XhtmlTextWriter xtw = new XhtmlTextWriter(sw);
GridView2.RenderControl(xtw);
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
bind();
}
public override void VerifyRenderingInServerForm(Control control) { }
using System.IO;
/// <summary>
/// 以下为数据导出代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkButton5_Click(object sender, EventArgs e)
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.ClearContent();//清除缓存区内容
Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.AppendHeader("content-disposition", "attachment; filename=MyExcelFile.xls;
Response.ContentType = "myexcel/excel";//设置输出流的类型
StringWriter sw = new StringWriter();//写入流
XhtmlTextWriter xtw = new XhtmlTextWriter(sw);
GridView2.RenderControl(xtw);
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
bind();
}
public override void VerifyRenderingInServerForm(Control control) { }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询