Created
September 12, 2016 06:46
-
-
Save johnsonz/e8daf2f2b330cc1b2737cd536507c1eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool ExportExcel(Page page, string FileName, string SheetName, string ContentBody) | |
{ | |
try | |
{ | |
string content = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + SheetName + "</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo /></x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>" + ContentBody + "</body></html>"; | |
page.Response.Buffer = true; | |
page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + DateTime.Now.ToString("yyyyMMdd") + ".xls"); | |
page.Response.ContentEncoding = System.Text.Encoding.UTF8; | |
page.Response.ContentType = "application/vnd.ms-excel"; | |
page.EnableViewState = false; | |
page.Response.Write(content); | |
page.Response.End(); | |
return true; | |
} | |
catch | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment