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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Asp.net 匯出ExcelASP.NETExcel
- ASP.NET Excel匯入和匯出ASP.NETExcel
- ASP.NET EXCEL資料的匯出和匯入ASP.NETExcel
- asp.net 利用NPOI匯出Excel通用類ASP.NETExcel
- 前端常用方法之匯出excel表格前端Excel
- 使用 Laravel-Excel 和流的方法匯出 ExcelLaravelExcel
- 匯出excelExcel
- asp.net framework4.0 使用NOPI(一)匯出excelASP.NETFrameworkExcel
- asp.net中利用NPOI匯出資料到excel中ASP.NETExcel
- 基於NPOI封裝匯出Excel方法封裝Excel
- vue excel匯入匯出VueExcel
- js匯出EXCELjs匯出EXCELJSExcel
- 【xiaomi】ASP.NET 分Sheet匯出EXCEL 2003ASP.NETExcel
- ASP.NET 2.0匯出到Excel時保留換行的方法ASP.NETExcel
- PHP 匯出 ExcelPHPExcel
- PHP匯出EXCELPHPExcel
- Vue匯出ExcelVueExcel
- Java匯出ExcelJavaExcel
- php 匯出excelPHPExcel
- POI 匯出ExcelExcel
- vue匯出excel(簡單方法完整介紹)VueExcel
- java匯出Excel定義匯出模板JavaExcel
- Excel模板匯出之動態匯出Excel
- Angular Excel 匯入與匯出AngularExcel
- Asp.net中使用以下程式碼匯出Excel表格(轉)ASP.NETExcel
- 騰訊文件怎樣匯出excel表格 騰訊文件如何匯出excelExcel
- Java 通過Xml匯出Excel檔案,Java Excel 匯出工具類,Java匯出Excel工具類JavaXMLExcel
- js匯出Excel表格JSExcel
- vue匯出Excel表格VueExcel
- Excel優雅匯出Excel
- Excel匯出實列Excel
- Springmvc匯出excelSpringMVCExcel
- appfuse:Excel匯出APPExcel
- DataGridView匯出ExcelViewExcel
- vue 前端匯出 excelVue前端Excel
- poi的excel匯出Excel
- C#快速匯出百萬級資料到Excel方法C#Excel
- ASP.NET MVC 匯入Excel檔案ASP.NETMVCExcel