新建一个页面在page_load事件中写:
try
{
if(!PageIsPostBack)
{
string strFileName=;
strFileName=RequestQueryString[FILE_NAME]ToString();
strFileName=HttpUtilityUrlEncode(SystemTextEncodingUTFGetBytes(strFileName));
ResponseClear();
ResponseContentType=application/xmsexcel;
ResponseAddHeader(ContentDispositioninline;filename=+strFileName);
SystemIOFileStreamMyFileStream=newFileStream(RequestQueryString[REPORT_FILE]ToStrin()SystemIOFileModeOpenSystemIOFileAccessReadSystemIOFileShareRead);
longFileSize=MyFileStreamLength;
byte[]Buffer=newbyte[(int)FileSize];
MyFileStreamRead(Buffer(int)FileSize);
MyFileStreamClose();
ResponseBinaryWrite(Buffer);
}
}
catch(Exceptionexp)
{
ResponseWrite(导出数据错误!);
}
在前面一个页面完成数据填入工作并调用上面页面:
stringBuffer=thistheucExportExcelLogicSetDataToExcel(this_ExportDatathis_ExportHeaderDatastrFileNamethis_HeaderType this_OnlyVisible);
ResponseClear();
ResponseRedirect(//ExportExcel/ShowReportaspx?REPORT_FILE=+Buffer+&FIlE_NAME=+this_OutFileNametrue);