sql数据输出到word
这个很简单,直接把显示到屏幕的网页输出到word文件就可以了,下面是一个ASP示例. .....连接数据库 Response.ContentType="application/msword"'输出到word文件 Response.AddHeader "content-disposition","attachment;filename=test.doc"'生成word的文件名 set pa=conn.execute(select * from table) do while not pa.eof response.write pa(0)&"," response.write pa(1)&"" pa.movenext loop pa.close %>
asp.net导出word
public void Download(){Random rd = new Random();string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";//存储路径string path = Server.MapPath(fileName);//创建字符输出流StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);//需要导出的内容string str = "无标题文档这里放从数据库导出的word文档内容";//写入sw.Write(str);sw.Close();Response.Clear();Response.Buffer = true;this.EnableViewState = false;Response.Charset = "utf-8";Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));Response.ContentType = "application/octet-stream";Response.WriteFile(path);Response.Flush();Response.Close();Response.End();}标准word文档的格式微软暂未公布,由此我们可将需要导出的内容转为标准HTML文件储存,后缀名为.doc也可以将要导出内容转为标准XML格式存储,改后缀为.doc具体格式随意新建个word文档,输入内容,另存为.XML可见另外一种导出方式为word导出标准格式,服务器需要安装Microsoft Office word,需要预先设置好一个word文档并在要插入内容的地方设置书签做为模版,导出word文档时需要先遍历模版文件中的所有书签,然后给书签赋值就能实现导出数据了还有不懂的可以直接百度HI我是否可以解决您的问题?
如何将asp查询结果输出为excel表格
生成EXCEL文件 Response.Expires =-1 Response.ExpiresAbsolute = Now() - 1 Response.cachecontrol = "no-cache" Set fs = server.CreateObject("scripting.filesystemobject") '--假设你想让生成的EXCEL文件做如下的存放 filename="Regist_Exhi"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&".xls" filename1="EXECL/"&filename filename=Server.MapPath(filename1) '--如果原来的EXCEL文件存在的话删除它 if fs.FileExists(filename) then fs.DeleteFile(filename) end if '--创建EXCEL文件 set myfile = fs.CreateTextFile(filename,true) dim strLine,responsestr strLine="" '得到表的列名 strLine=strLine & "公司名称"& chr(9) strLine=strLine & "姓名"& chr(9) strLine=strLine & "工作职务"& chr(9) strLine=strLine & "所在国家"& chr(9) strLine=strLine & "所在城市"& chr(9) strLine=strLine & "地址"& chr(9) strLine=strLine & "邮政编码"& chr(9) strLine=strLine & "电话"& chr(9) strLine=strLine & "传真"& chr(9) strLine=strLine & "手机"& chr(9) strLine=strLine & "电子邮箱"& chr(9) strLine=strLine & "网址"& chr(9) strLine=strLine & "行业性质"& chr(9) strLine=strLine & " "& chr(9) strLine=strLine & "渠道获得"& chr(9) strLine=strLine & "报名流水号"& chr(9) strLine=strLine & "报名时间"& chr(9) '--将表的列名先写入EXCEL myfile.writeline strLine Set rs = Server.CreateObject("ADODB.Recordset") '--从数据库中把你想放到EXCEL中的数据查出来 sql="Select * from Regist_Exhi where Area="&Request("Pid")&" order by id Desc" rs.Open sql,conn if Not rs.EOF then Do while Not rs.EOF strLine = Rs("company") & chr(9) strLine =strLine & Rs("gname") & Rs("sex")& chr(9) strLine =strLine & Rs("jobtitle") & chr(9) strLine =strLine & Rs("country") & chr(9) strLine =strLine & Rs("city")& chr(9) strLine =strLine & Rs("address") & chr(9) strLine =strLine & Rs("postal") & chr(9) strLine =strLine & Rs("phone") & chr(9) strLine =strLine & Rs("fax") & chr(9) strLine =strLine & Rs("mobile") & chr(9) strLine =strLine & Rs("email")& chr(9) strLine =strLine & Rs("http") & chr(9) strLine =strLine & Rs("trade")&rs("tradeElse")& chr(9) strLine =strLine & Rs("auspice") & Rs("show")& chr(9) strLine =strLine & Rs("modes")&rs("modeElse")& chr(9) strLine =strLine & "*"&Rs("SystemNO") & chr(9) strLine =strLine & Rs("addtime") & chr(9) '--将表的数据写入EXCEL myfile.writeline strLine rs.MoveNext loop end if rs.Close set rs=nothing set conn = nothing set myfile = nothing Set fs=Nothing Response.Redirect filename1%>
在ASP中怎么把页面中的数据导出到EXCEL
在想导出结果的页面顶部加上以下代码即可:<%Response.ContentType = "application/msword"Response.AddHeader "Content-Disposition", "attachment;filename="记录"&year(now)&month(now)&day(now)&".xls"%>
转载请注明出处51数据库 » asp数据库导出word