好久没来了,100高分求教个问题?数据导出excel问题

lionz1023 2013-01-31 10:20:04

<!--#include file="inc/sys_conn.asp"-->
<%
Set fs = server.CreateObject("scripting.filesystemobject")
a=year(now())&"-"&month(now())&"-"&day(now())
filename = Server.MapPath("/pqyg/date/pqyg_"&a&".xls")
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if

set myfile = fs.CreateTextFile(filename,true)

strSql = "select * from person where p_state<>'离职'"
Set rstData =conn.execute(strSql)
if not rstData.EOF and not rstData.BOF then

dim trLine,responsestr
strLine=""
For each x in rstData.fields
strLine = strLine & x.name & chr(9)
Next

'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rstData.EOF
strLine=""

for each x in rstData.Fields
strLine = strLine &"'"& x.value & "'"& chr(9)
next
myfile.writeline strLine

rstData.MoveNext
loop

end if

Response.Write "生成EXCEL文件成功,点击<a href=""/pqyg/date/pqyg_"&a&".xls"" target=""_blank"">下载</a>!"

rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
%>

现在有个问题,里面有一个身份证字段,导出后默认成了数字,显示成了科学计数法,搜了下加上单引号后是可以正常现在,但是其他字段也会出现单引号,求解如何绝佳这个问题,另外导出的表头是字段,但是我设置的是因为,想用中问该如何解决?
...全文
237 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
来学习一下,呵呵。
fzfei2 2013-01-31
  • 打赏
  • 举报
回复
引用 2 楼 lionz1023 的回复:
引用 1 楼 fzfei2 的回复:strLine = strLine &amp;""""&amp; x.value &amp; """"&amp; chr(9) 改成这样试试 不行啊
生成table这格式,这样可以加样式 <table border="1"> <tr> <!-- 这循环开始 --> <td style='mso-number-format:"\@"'>123456789065432</td> <!-- 这循环结束 --> </tr> </table>
lzp4881 2013-01-31
  • 打赏
  • 举报
回复
你可以加一个判断,如果字段名称是身份证,就加单引号,如果不是就不加 for each x in rstData.Fields if x.name="身份证" then strLine = strLine & "'" end if strLine = strLine & x.value & chr(9) next
Go 旅城通票 2013-01-31
  • 打赏
  • 举报
回复
excel处理数字的问题,一串数字会被显示为科学计数法 你可以区别判断下是身份证的时候再用''括起数据 标头的话除非数据库字段名称为中文的,要不就需要些一个辅助函数从英文还原为中文的
Set fs = server.CreateObject("scripting.filesystemobject")  
a=year(now())&"-"&month(now())&"-"&day(now())    
filename = Server.MapPath("/pqyg/date/pqyg_"&a&".xls")  
if fs.FileExists(filename) then  
    fs.DeleteFile(filename)  
end  if  
  
set myfile = fs.CreateTextFile(filename,true)  

function cnname(v)'''''''''
 select case  v
   case "name"  cnname="姓名"
   case "idcard"  cnname="身份证"
   '.....其他case语句
 end select
end function

strSql = "select * from person where p_state<>'离职'"
Set rstData =conn.execute(strSql)
if not rstData.EOF and not rstData.BOF then  
  
    dim  trLine,responsestr  
    strLine=""  
    For each x in rstData.fields  
        strLine = strLine & cnname(x.name) & chr(9)  ''''''''''
   Next  
  
'--将表的列名先写入EXCEL  
    myfile.writeline strLine  
  
    Do while Not rstData.EOF  
        strLine=""  
  
        for each x in rstData.Fields  
            if x.name="idcard" then''''''''修改对应的身份证字段名称
              strLine = strLine &"'"& x.value & "'"& chr(9) 
            else
              strLine = strLine & x.value & chr(9) 
            end if 
        next  
        myfile.writeline  strLine  
  
        rstData.MoveNext  
    loop  
  
end if  
 
Response.Write  "生成EXCEL文件成功,点击<a href=""/pqyg/date/pqyg_"&a&".xls"" target=""_blank"">下载</a>!"
 
rstData.Close  
set rstData = nothing
Conn.Close
Set Conn = nothing
lionz1023 2013-01-31
  • 打赏
  • 举报
回复
引用 1 楼 fzfei2 的回复:
strLine = strLine &""""& x.value & """"& chr(9) 改成这样试试
不行啊
fzfei2 2013-01-31
  • 打赏
  • 举报
回复
strLine = strLine &""""& x.value & """"& chr(9)   改成这样试试
lionz1023 2013-01-31
  • 打赏
  • 举报
回复
谢谢大家了,虽然老大要求的身份证也不要带引号 看来是没万全办法了。

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧