62,073
社区成员
发帖
与我相关
我的任务
分享
protected void btnToExel_Click( object sender, EventArgs e )
{
DataSet ds = new DataSet();
ds = GetDataSet();
if ( ds.Tables[ 0 ].Rows.Count > 0 ) {
this.grdMedicine.DataSource = this.GetDataSet().Tables[ 0 ].DefaultView;
this.grdMedicine.DataBind();
}
GridViewExportUtil.Export( this.grdMedicine,"phk.xls" );//导出方法
//判断一下文件是否存在
if(File.Exists("phk.xls")) //文件存在
{
DELETE();
}
}
HttpResponse hr = Page.Response;
hr.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
hr.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.csv", HttpUtility.UrlEncode(DateTime.Now.ToShortDateString());
string ls_item = "";
//获取标题
string header = "表头,表头,表头,表头,表头\n";
hr.Write(header);
hr.Write("表头,表头,表头,表头,表头");//这里的内容,可循环你的DataSet来实现,加上\n表示换行
hr.End();