2012-07-24 78 views
2

我有一個經典的asp網站,其中包括將表格數據導出/下載爲excel文件(.xls)的功能。這是通過代替通常的HTML頭將用戶重定向到與這個代碼塊的新頁面進行:經典ASP內容類型XLS Chrome下載爲某些用戶的.asp文件

sub PutInTopOfXLS(FileName) 
    Response.Buffer = TRUE 
    Response.CharSet="UTF-8" 
    Response.CodePage=65001 
    Response.ContentType = "application/vnd.ms-excel" 
    Response.AddHeader "Content-Disposition", "attachment;filename=" & FileName%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns:x="urn:schemas-microsoft-com:office:excel"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <style> 
     <!--table 
     br {mso-data-placement:same-cell;} 
     tr {vertical-align:top;} 
     --> 
     </style> 
    </head> 
    <body> 
<%end sub 

能正常工作的所有用戶(或至少沒有問題的報告)在Firefox, Internet Explorer和Safari(適用於Mac和Windows),它適用於使用Chrome(20.0.1132.57)的開發計算機。但是,我的質量檢查人員報告說,在網站上的幾個特定報告中,它始終在Chrome上下載實際代碼頁名稱ReportFileName.asp,然後得到一個關於.asp文件沒有文件關聯的Windows錯誤。如果他實際選擇了使用Excel打開,則下載了正確的文件。我問我們辦公室的另一個人下載Chrome,她沒有問題;該文件下載爲{filename} .xls並正常打開。

我很困惑,因爲對於質量保證人員來說,隻影響這一份報告就會表明問題出在具體的報告中。但是,其他兩位使用相同版本Chrome的用戶並沒有遇到問題,這表明這是Chrome設置中的一些內容。

我沒有任何運氣谷歌搜索解決方案或搜索所以我想我會拋出這個問題,看看有沒有人有任何想法。

非常感謝您的協助。

回答

0

我建議流式傳輸文件,這將允許您以更好的方式處理大型文件。

這是我的工作的例子,我用這個去接其存儲在一個相當不友好的文件名一些自動化的CSV文件,我也使用這個腳本提出一個更好的文件名到最終用戶:

' Set some variables 
strSourceFilename = "00008446.dat" 
strNiceFilename = "Nice Name Here.csv" 

' Read the file and stream it back to the client 
Const adTypeBinary = 1 
Set BinaryStream = CreateObject("ADODB.Stream") 
BinaryStream.Type = adTypeBinary 
BinaryStream.Open 
BinaryStream.LoadFromFile "C:\path\to\the\folder\" & strSourceFilename 
ReadBinaryFile = BinaryStream.Read 
Response.ContentType = "application/x-unknown" 
Response.AddHeader "Content-Disposition", "attachment; filename=" & strNiceFilename 
Response.BinaryWrite ReadBinaryFile 

希望這有助於!