日期:2014-05-17  浏览次数:20404 次

怎样把Microsoft.Office.Interop.Excel.ApplicationClass excel创建的文件保存到数据流中
在点击“导出”按钮时,生成一个excel格式的文件,现在不想把excel保存到本地目录上,而是想保存成文件流,以便Response.WriteFile()

------解决方案--------------------
再从文件读一遍。
------解决方案--------------------
学习 帮顶
------解决方案--------------------
private void FileDownload(string fName,string path)
{
long lngFileSize;
byte[] bytBuffer;
int iReading;
string sFileName=Server.MapPath(path+fName);
Stream outStream= Response.OutputStream;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Connection","keep-alive");
Response.AppendHeader("Content-Disposition","attachment; filename="+fName);
FileStream fStream= new FileStream(sFileName,FileMode.OpenOrCreate,FileAccess.Read);
lngFileSize =fStream.Length;
bytBuffer =new byte[(int)lngFileSize];
while((iReading=fStream.Read(bytBuffer,0,(int)lngFileSize))> 0)
{
outStream.Write(bytBuffer,0,iReading);
}
fStream.Close();
outStream.Close();
}
------解决方案--------------------
帮顶