本文介绍了打开Excel在asp.net文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图打开从asp.net.The $ C $词现在用的就是here.It给出的Excel(.xls)文件则呈现出保存作为我不想。请帮我对话框! !
Response.ContentType =应用程序/ XLS
Response.Flush();
Response.WriteFile(文件名);
到Response.End();
解决方案
尝试添加response.addheader并使用binarywirte而不是写文件到你code像下面的示例code(工作code)...
System.IO.FileStream FS = NULL;
FS = System.IO.File.Open(文件名,System.IO.FileMode.Open); 字节[] = btFile新的字节[fs.Length]
fs.Read(btFile,0,Convert.ToInt32(fs.Length));
fs.Close();
Response.AddHeader(内容处置,附件;文件名=+文件名);
Response.ContentType =应用程序/八位字节流;
Response.BinaryWrite(btFile);
到Response.End();
I am trying to open a Excel(.xls) file from asp.net.The code i am using is given here.It is showing a save as dialog box which i don't want .Please help me !!!
Response.ContentType = "application/xls";
Response.Flush();
Response.WriteFile(fileName);
Response.End();
解决方案
Try adding response.addheader and use "binarywirte" instead of "writeFile" to your code like below sample code(working code) ...
System.IO.FileStream fs = null;
fs = System.IO.File.Open(filename, System.IO.FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.AddHeader("Content-disposition", "attachment; filename=" + filename);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(btFile);
Response.End();
这篇关于打开Excel在asp.net文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!