62,271
社区成员
发帖
与我相关
我的任务
分享
//点击打印事件
protected void Img_DCExcel_Click(object sender, ImageClickEventArgs e)
{
Export("application/ms-excel", "订单金额明细表.xls");
}
/// <summary>
/// 定义导出Excel的函数
/// </summary>
/// <param name="FileType"></param>
/// <param name="FileName"></param>
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.Default).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
int n = this.GView_InStoreNote.Columns.Count;//GView_InStoreNote,你的控件名字
this.GView_InStoreNote.HeaderRow.Cells[n - 1].Visible = false;
for (int i = 0; i < this.GView_InStoreNote.Rows.Count; i++)
{
this.GView_InStoreNote.Rows[i].Cells[n - 1].Visible = false;
//this.GView_CJCGList.Rows[]
}
this.GView_InStoreNote.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
/// <summary>
/// 此方法必重写,否则会出错
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
}
