导出*.csv的xls时出现乌龙事件
[ 2010-04-16 09:19:16 | 作者: admin ]
本来导出一个csv也是家常便饭的事情,今天花了2个小时就是搞不定,出现“无法下载”的提示。
无论怎么修改header就是不行,本地测试绝对正常,传到服务器上就报错。
直接在服务器上测试发现报500错误,才知道程序有问题,去掉Response.ContentType = "application/ms-excel" 后找到错误原因:自己本地加了函数服务器没有同步更新。
原来做文件输出的时候,浏览器关闭友好提示,500错误就不会出现了,容易对调试程序产生误导。
程序参考
无论怎么修改header就是不行,本地测试绝对正常,传到服务器上就报错。
直接在服务器上测试发现报500错误,才知道程序有问题,去掉Response.ContentType = "application/ms-excel" 后找到错误原因:自己本地加了函数服务器没有同步更新。
原来做文件输出的时候,浏览器关闭友好提示,500错误就不会出现了,容易对调试程序产生误导。
程序参考
'*************************
'导出excel文件
'*************************
if request.Form("act")="ExportExcel" then
'输出文件头
Response.Buffer = true
Response.Charset = "gb2312"
Response.ContentType = "application/ms-excel"
'Response.ContentType = "application/force-download"
'Response.ContentType = "application/download"
Response.AddHeader "Content-Disposition", "attachment;filename=Excel"& year(now())&""&month(now())&""&day(now()) &".csv"
'确保IE识别本次为下载文件
Response.AddHeader "Content-Transfer-Encoding","binary"
Response.AddHeader "Cache-Control","must-revalidate, post-check=0, pre-check=0"
Response.AddHeader "Pragma","public"
str = "网站"&","&"域名"&","&"邮箱"&","&"时间"&","&"备注" & chr(13) & chr(10) '注意以逗号分隔
str = str & validStrForCsv("Tao123好网站推荐") &","& validStrForCsv("http://www.52News.com")&","&validStrForCsv("cxosoft@gmail.com")&","&validStrForCsv("2002-04-10")&","&validStrForCsv("今天天气真好,电子公告终于批下来了!!") & chr(13) & chr(10)
response.Write(str)
response.End()
end if
'导出excel文件
'*************************
if request.Form("act")="ExportExcel" then
'输出文件头
Response.Buffer = true
Response.Charset = "gb2312"
Response.ContentType = "application/ms-excel"
'Response.ContentType = "application/force-download"
'Response.ContentType = "application/download"
Response.AddHeader "Content-Disposition", "attachment;filename=Excel"& year(now())&""&month(now())&""&day(now()) &".csv"
'确保IE识别本次为下载文件
Response.AddHeader "Content-Transfer-Encoding","binary"
Response.AddHeader "Cache-Control","must-revalidate, post-check=0, pre-check=0"
Response.AddHeader "Pragma","public"
str = "网站"&","&"域名"&","&"邮箱"&","&"时间"&","&"备注" & chr(13) & chr(10) '注意以逗号分隔
str = str & validStrForCsv("Tao123好网站推荐") &","& validStrForCsv("http://www.52News.com")&","&validStrForCsv("cxosoft@gmail.com")&","&validStrForCsv("2002-04-10")&","&validStrForCsv("今天天气真好,电子公告终于批下来了!!") & chr(13) & chr(10)
response.Write(str)
response.End()
end if
[最后修改由 admin, 于 2010-04-16 09:41:26]
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1383
这篇日志没有评论。
此日志不可发表评论。