急求:如何从asp中将数据插入到excel中不同的表单中

njhyh 2005-07-21 05:56:25
我在excel中有两个表单,sheet1和sheet2。
我如何能将不同的数据插入到不同的表单中.
例如;“xingming”字段值 我要插入到sheet1中
“age”字段值 我要插入到sheet2中
急求.....
...全文
226 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
njhyh 2005-07-23
  • 打赏
  • 举报
回复
自己解决了!谢谢大家了!
IT_Fish 2005-07-22
  • 打赏
  • 举报
回复
1、 建立Excel对象
set objExcelApp = CreateObject("Excel.Application")
objExcelApp.DisplayAlerts = false 不显示警告
objExcelApp.Application.Visible = false 不显示界面
2、 新建Excel文件
objExcelApp.WorkBooks.add
set objExcelBook = objExcelApp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set objExcelSheet = objExcelBook.Sheets(1)
tigerwen01 2005-07-22
  • 打赏
  • 举报
回复
<%@ LANGUAGE="VBSCRIPT" %>
<%option explicit%>
<HTML>
<HEAD>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<a href="dbtoexcel.asp?act=make">生成EXCEL文件</a>
<hr size=1 align=left width=300px>
<%
if Request("act") = "" then
Response.Write "生成EXCEL文件"
else

dim conn,strconn
strconn="driver={SQL Server};server=xxx;uid=sa;pwd=;database=DB_Test"
set conn=server.CreateObject("adodb.connection")
conn.Open strconn

dim rs,sql,filename,fs,myfile,x

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("online.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
sql = "select * from Tb_Execl order by sort desc"
rs.Open sql,conn
if rs.EOF and rs.BOF then
Response.Write "库里暂时没有数据!"
else
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next

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

Do while Not rs.EOF
strLine=""

for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine

rs.MoveNext
loop
end if
rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing
end if
%>
</BODY>
</HTML>
游陆 2005-07-22
  • 打赏
  • 举报
回复
关注!
白夜花寒 2005-07-22
  • 打赏
  • 举报
回复
set objExcelSheet2 = objExcelBook.Sheets(2)

不过vba的效率不如用ado了,还有用vba要注意的
开始-》运行 输入dcomcnfg-》组件服务-》计算机-》我的电脑-》DCOM配置-》Microsoft Excel 文档-》右键属性-》安全访问权限里加上everyone 标识里加入交互式用户

http://www.connectionstrings.com/ 参考这个网站的连接符

28,409

社区成员

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

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