protected void BtnExport_Click(object sender, EventArgs e) { DateTime dt = DateTime.Now; Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + string.Format("{0:yyyyMMddHHmmss}", dt) + ".xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.Page.EnableViewState = false; GVData.AllowPaging = false; GVData.Columns[15].Visible = false; GVDataDataBind(); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); GVData.Page.EnableViewState = true; GVData.AllowPaging = true; GVData.Columns[15].Visible = true; GVDataDataBind(); }
protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { if (this.RadioButtonList1.SelectedItem.Text == "电子表格") { DisableControls(GVData); Response.ClearContent(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + ".xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } else { DisableControls(GVData); Response.ClearContent(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + ".htm"); Response.ContentType = "text/HTML"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } }
protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { DisableControls(GVData); Response.ClearContent(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToShortDateString() + ".xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
protected void BtnHtmlToExcel_Click(object sender, EventArgs e) { Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=wuzixuqiu.xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.AllowPaging = false; GVData.Columns[GVData.Columns.Count - 2].Visible = false; GVData.Columns[GVData.Columns.Count - 1].Visible = false; GVDataBind(); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); GVData.AllowPaging = true; GVData.Columns[GVData.Columns.Count - 2].Visible = true; GVData.Columns[GVData.Columns.Count - 1].Visible = true; GVDataBind(); }
protected void BtnExportExcel_Click(object sender, EventArgs e) { DateTime dt = DateTime.Now; Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + string.Format("{0:yyyyMMddHHmmss}", dt) + ".xls"); Response.ContentType = "application/excel"; Response.Write(@"<style> .TextCell {mso-number-format:\@;}</style>"); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GVData.AllowPaging = false; query(); GVData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); GVData.AllowPaging = true; query(); }