我以流形式向页面输出excel,我想实现浏览的时侯自动打开excel,
而不是弹出对话框提示保存还是打开,怎么修正。。
Response.Clear()
Response.Buffer = True
Response.Charset = "utf-8 "
Dim fileStream As FileStream = New FileStream( "C:\\11.xls ", FileMode.Open)
Dim fileSize As Long = fileStream.Length
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " & filename)
Response.AppendHeader( "Content-Length ", fileSize.ToString())
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ")
Response.ContentType = "application/ms-excel "
Dim fileBuffer() As Byte
ReDim fileBuffer(fileSize)
fileStream.Read(fileBuffer, 0, fileSize)
Context.Response.BinaryWrite(fileBuffer)
Context.Response.End()
------解决方案--------------------Response.AppendHeader( "Content-Disposition ", "inline;filename= " & filename)
不过安全的浏览器,或者浏览器安全级比较适当,仍然会给一个提示。
打开Excel文件是非常危险的动作。Excel文件中可以隐藏任何流氓软件代码,文档中可以嵌入VBA写的或者其它编译为DLL的代码。