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

保存excel文件出现乱码,在线等!!!
with   response
.buffer   =   true
.AddHeader   "Content-Disposition ",   "attachment;   fileName= "   &   request.Form( "sToExcel ")   &   ".xls "
.ContentType   =   "application/vnd.ms-excel "
.Flush
End   with

使用上面的代码将查询结果集保存成Excel文件,但是有时中文会出现乱码。原来以为和记录数有关,但是后来减少记录数了,仍然存在这个问题。是否与excel文件的列数有关?我把excel文件的列数减半就不会出现乱码了。
请各位大侠多多指教,谢谢!

------解决方案--------------------
一般这种情况是缓存的问题,只要在文件头加上如下代码即可:

Response.Clear() '这一句和下面这一句很重要
response.Charset = "gb2312 " '这一句很重要
Server.ScriptTimeOut = 999999 '设定超时时间长些
response.Buffer=true
Response.ContentType = "application/vnd.ms-excel "
------解决方案--------------------
我有asp导出excel的,大数据量速度特别快.
修改以前的.三个文件
di.txt,tou.txt,OutExcel.asp
第一个di.txt
---------------------
<table x:str border=0 cellpadding=0 cellspacing=0 width=288 style= 'border-collapse:
collapse;table-layout:fixed;width:216pt '>
<![if supportMisalignedColumns]>
<tr height=0 style= 'display:none '>
<td width=72 style= 'width:54pt '> </td>
<td width=72 style= 'width:54pt '> </td>
<td width=72 style= 'width:54pt '> </td>
<td width=72 style= 'width:54pt '> </td>
</tr>
<![endif]>
</table>
-----------------------------------------------
第二个tou.txt
-----------------------------------------------
<html xmlns:o= "urn:schemas-microsoft-com:office:office "
xmlns:x= "urn:schemas-microsoft-com:office:excel "
xmlns= "http://www.w3.org/TR/REC-html40 ">

<head>
<meta http-equiv=Content-Type content= "text/html; charset=GB2312 ">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content= "Microsoft Excel 9 ">
<link rel=File-List href= "./222.files/filelist.xml ">
<link rel=Edit-Time-Data href= "./222.files/editdata.mso ">
<link rel=OLE-Object-Data href= "./222.files/oledata.mso ">
<!--[if gte mso 9]> <xml>
<o:DocumentProperties>
<o:Author> xky </o:Author>
<o:LastAuthor> xky </o:LastAuthor>
<o:Created> 2002-05-27T17:51:00Z </o:Created>
<o:LastSaved> 2002-06-22T10:03:03Z </o:LastSaved>
<o:Company> zydn </o:Company>
<o:Version> 9.2812 </o:Version>
</o:DocumentProperties>
<o:OfficeDocumentSettings>
<o:DownloadComponents/>
<o:LocationOfComponents HRef= "file:///E:/msowc.cab "/>
</o:OfficeDocumentSettings>
</xml> <![endif]-->
<style>
<!--table
{mso-displayed-decimal-separator: "\. ";
mso-displayed-thousand-separator: "\, ";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
tr
{mso-height-source:auto;
mso-ruby-visibility:none;}
col
{mso-width-source:auto;
mso-ruby-visibility:none;}
br
{mso-data-placement:same-cell;}
.style0
{mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
mso-rotate:0;
mso-background-s