asp.net Excel匯出方法
Response.ClearHeaders();
Response.Clear();
Response.Expires = 0;
Response.Buffer = true;
Response.Charset = "UTF-8";
//把 attachment 改為 online 則線上開啟
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + FileName + "\"");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
string[] keyValue = sFileName.Split(".".ToCharArray());
if (keyValue.Length >= 2)
{
string type = (string)((keyValue[keyValue.Length - 1]).ToString());
Response.ContentType = GetResponseContentType(type);
}
//獲取byte格式檔案從資料庫
byte[] bt = (byte[])DownLoadFile(Convert.ToDateTime(Server.UrlDecode(Request["SaveTime"])));
if (bt.Length == 0)
{
byte[] tempArray = new byte[1];
tempArray[0] = Convert.ToByte(' ');
bt = tempArray;
}
Response.OutputStream.Write(bt, 0, bt.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.End();
Response.Clear();
Response.Expires = 0;
Response.Buffer = true;
Response.Charset = "UTF-8";
//把 attachment 改為 online 則線上開啟
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + FileName + "\"");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
string[] keyValue = sFileName.Split(".".ToCharArray());
if (keyValue.Length >= 2)
{
string type = (string)((keyValue[keyValue.Length - 1]).ToString());
Response.ContentType = GetResponseContentType(type);
}
//獲取byte格式檔案從資料庫
byte[] bt = (byte[])DownLoadFile(Convert.ToDateTime(Server.UrlDecode(Request["SaveTime"])));
if (bt.Length == 0)
{
byte[] tempArray = new byte[1];
tempArray[0] = Convert.ToByte(' ');
bt = tempArray;
}
Response.OutputStream.Write(bt, 0, bt.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.End();
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25897606/viewspace-712515/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 前端常用方法之匯出excel表格前端Excel
- 使用 Laravel-Excel 和流的方法匯出 ExcelLaravelExcel
- 匯出excelExcel
- 基於NPOI封裝匯出Excel方法封裝Excel
- vue excel匯入匯出VueExcel
- Java匯出ExcelJavaExcel
- Vue匯出ExcelVueExcel
- PHP 匯出 ExcelPHPExcel
- PHP匯出EXCELPHPExcel
- vue匯出excel(簡單方法完整介紹)VueExcel
- ASP.NET MVC 匯入Excel檔案ASP.NETMVCExcel
- java匯出Excel定義匯出模板JavaExcel
- Excel模板匯出之動態匯出Excel
- Angular Excel 匯入與匯出AngularExcel
- Excel匯出實列Excel
- js匯出Excel表格JSExcel
- vue 前端匯出 excelVue前端Excel
- poi的excel匯出Excel
- vue匯出Excel表格VueExcel
- Excel優雅匯出Excel
- C#快速匯出百萬級資料到Excel方法C#Excel
- vue + element + 匯入、匯出excel表格VueExcel
- kxcel, 方便匯入和匯出 ExcelExcel
- Vue框架下實現匯入匯出Excel、匯出PDFVue框架Excel
- 騰訊文件怎樣匯出excel表格 騰訊文件如何匯出excelExcel
- .NET CORE 2.1 匯出excel檔案的兩種方法Excel
- SQL Server 匯出Excel有換行的解決方法SQLServerExcel
- element-ui 匯出excelUIExcel
- springboot poi匯出excel表格Spring BootExcel
- Mvc 5中匯出ExcelMVCExcel
- excel匯出、mysql分頁ExcelMySql
- Go 使用反射匯出 ExcelGo反射Excel
- Laravel Excel3.0匯出LaravelExcel
- oracle 匯出excel 格式整改OracleExcel
- java匯出Excel檔案JavaExcel
- PhpSpreadsheet 匯出excel範例PHPExcel
- 如何使用 JavaScript 匯入和匯出 ExcelJavaScriptExcel
- EasyPoi, Excel資料的匯入匯出Excel
- Vue + Element 實現匯入匯出ExcelVueExcel