1. 用這個函數 SaveExcelToResponse
2. 也可以 用SaveExcel
public static void outputExcel(FpSpread inSpread, HttpResponse Response)
{
string filename = System.Guid.NewGuid().ToString() + ".xls";
string strFullPath = string.Empty;
strFullPath = System.Web.HttpContext.Current.Server.MapPath("../Upload/" + filename);
inSpread.SaveExcel(strFullPath, FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
OutpubExcelFile(strFullPath, filename, Response);
}
private static void OutpubExcelFile(string absolutePath, string filename, HttpResponse Response)
{
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-7");
Response.ContentType = "application/ms-excel";
FileStream MyFileStream = new FileStream(absolutePath, FileMode.Open);
long FileSize = MyFileStream.Length;
byte[] buffer = new byte[(int)FileSize];
MyFileStream.Read(buffer, 0, (int)FileSize);
MyFileStream.Close();
Response.BinaryWrite(buffer);
Response.Flush();
} |