asp.net 输出Excel
private void lbtExportToExcel_Click(object sender, EventArgs e) { string strdate = DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/" + DateTime.Now.Year.ToString(); strdate = (Convert.ToDateTime(strdate)).ToString("MMddyyyy"); string strFileName = "Organic Loyalist Summary Report " + strdate + ".xls"; StringWriter sw = new StringWriter(); string str = "field\t" + "smaple data"; sw.WriteLine(str); str = "Personally Enrolled Organic Loyalists:\t" + this.lblPEOLoyalists.Text; sw.WriteLine(str); str = "Number of Organic Loyalists in Downline:\t" + this.lblNOOLInDowline.Text; sw.WriteLine(str); str = "Organic Loyalists Sales:\t" + this.lblOLSales.Text; sw.WriteLine(str); sw.Close(); System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName); System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel"; System.Web.HttpContext.Current.Response.Write(sw); System.Web.HttpContext.Current.Response.End(); }