中易网

C#导出Excel文件,用的是SaveFileDialoge请教(急急急!!!)

答案:4  悬赏:0  
解决时间 2021-01-16 05:10
  • 提问者网友:最爱你的唇
  • 2021-01-16 00:08
C#导出Excel文件,用的是SaveFileDialoge请教(急急急!!!)
最佳答案
  • 二级知识专家网友:人類模型
  • 2021-01-16 00:52
private void btn_save_click(参数)
{
SaveFileDialoge sfd=new SaveFileDialoge();
if(sfd.filename!=string.empty;
{
ExportExcel(dt,sfd.filename);//从sfd对象取文件的存储路径呗
}
}
全部回答
  • 1楼网友:狂恋
  • 2021-01-16 02:33
你 导出的数据是全部还是第一页的啊!如果分页了之后!
  • 2楼网友:英雄的欲望
  • 2021-01-16 02:14
导出按钮btn_save_Click的onclick事件调用你的方法
protected void btn_save_Click(object sender, EventArgs e)
{
ExportExcel(DataTable dt,string path)
}
这样就可以调用你的方法了,把你的参数传进去
  • 3楼网友:你可爱的野爹
  • 2021-01-16 01:36
好简单,虽然只有5分,我还是给代码给你吧,你拿到代码直接用就行了。
private void Exp_Excel(DataTable dt)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer= true ;
HttpContext.Current.Response.AddHeader("content-disposition","attachment;filename=FileName3.xls");
//HttpContext.Current.Response.Charset = "GB2312";
//HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite);
DataGrid.AllowPaging = false;
DataGrid.DataSource = dt;
DataGrid.DataBind();

//导出标题
DataGrid.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();

DataGrid.AllowPaging = true;
DataGrid.AllowPaging = false;
DataGrid.DataSource = dt;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息