asp操作excel

xuyan9927 2007-04-11 02:39:03
需要用excel做数据库,不知道怎么写入数据到excel中
asp如何将数据写入一个已经存在的excel的固定列中???各位大狭帮忙啊???
...全文
2692 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
maguoliang123 2011-05-31
  • 打赏
  • 举报
回复
我也想知道
gahyyai 2008-07-01
  • 打赏
  • 举报
回复
我也想知道!!!
by792 2007-04-15
  • 打赏
  • 举报
回复
Set Conn = Server.CreateObject("ADODB.Connection")
Driveradd = "Driver=Microsoft excel Driver (*.xls);ReadOnly=false;dbq=C:\TEST.XLS"
Conn.Open Driveradd,3,3
set inputxq = Server.CreateObject("ADODB.Command")
inputxq.ActiveConnection = Conn
inputxq.CommandText = "INSERT INTO [sheet1$] ( a1) values ('1')
inputxq.CommandType = 1
inputxq.CommandTimeout = 0
inputxq.Prepared = true
inputxb.Execute()
yunxiang2005 2007-04-12
  • 打赏
  • 举报
回复
学习了!
bsnhk 2007-04-12
  • 打赏
  • 举报
回复
感谢daxuejianku(无言的悲伤),你的帖子正是我在找的,很详细,再次感谢!
lovexg1987 2007-04-12
  • 打赏
  • 举报
回复
佩服啊!~~学习!~~
xuyan9927 2007-04-11
  • 打赏
  • 举报
回复
你说的是新建立的一个EXCEL表格啊,如何将数据存储到现成的EXCEL文件中?
北京不不 2007-04-11
  • 打赏
  • 举报
回复
chouchy(城市刀客) ( ) 信誉:100 Blog 加为好友
已经说明..具体下面有个例子.
<!--#include file="conn.asp"-->
<%
Set xlApplication =server.CreateObject("Excel.Application") '调用excel对象
xlApplication.Visible = False '无需打开excel
xlApplication.SheetsInNewWorkbook=1 '指定excel中表的数量
xlApplication.Workbooks.Add '添加工作簿
Set xlWorksheet = xlApplication.Worksheets(1) '生成第1个工作表的子对象
xlWorksheet.name="统计" '指定工作表名称
'指定列的宽度以及对齐方式
xlApplication.ActiveSheet.Columns(1).ColumnWidth=5
xlApplication.ActiveSheet.Columns(1).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(1).font.bold=true
xlApplication.ActiveSheet.Columns(2).ColumnWidth=40
xlApplication.ActiveSheet.Columns(2).HorizontalAlignment=1
xlApplication.ActiveSheet.Columns(3).ColumnWidth=5
xlApplication.ActiveSheet.Columns(3).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(4).ColumnWidth=15
xlApplication.ActiveSheet.Columns(4).HorizontalAlignment=1
xlApplication.ActiveSheet.Columns(5).ColumnWidth=12
xlApplication.ActiveSheet.Columns(5).HorizontalAlignment=1
xlApplication.ActiveSheet.Columns(6).ColumnWidth=12
xlApplication.ActiveSheet.Columns(6).HorizontalAlignment=3
'xlApplication.ActiveSheet.Rows(i).RowHeight = 30'行的高度
'指定列的高度以及特定列
xlWorksheet.Range(xlWorksheet.Cells(1,1), xlWorksheet.Cells(2,6)).MergeCells =True '合并列
xlWorksheet.Range("A1").value="2005年统计"
xlWorksheet.Range("A1").font.Size=14'字体大小
xlWorksheet.Range("A1").font.bold=true'粗体
xlWorksheet.Range("A1").HorizontalAlignment=3'水平对齐
xlWorksheet.Range("A1").VerticalAlignment=3'垂直对齐

xlWorksheet.Cells(3,1).Value = "省"
xlWorksheet.Cells(3,2).Value = "城市"
xlWorksheet.Cells(3,3).Value = "姓名"
xlWorksheet.Cells(3,4).Value = "性别"
xlWorksheet.Cells(3,5).Value = "出生日期"
xlWorksheet.Cells(3,6).Value = "手机"

xlWorksheet.Range("A2:F2").Borders.LineStyle=1
Call openconn()
Dim sql
sql="select top 100 * from kehuziliao"
Set rs=conn.execute(sql)
Dim i
i=1
Do While Not rs.eof
'--------------------------------------------------自己可做循环i=i+1(数据库数据)
xlWorksheet.Cells(2+i,1).Value = rs("quyu")
xlWorksheet.Cells(2+i,2).Value = rs("chengshi")
xlWorksheet.Cells(2+i,3).Value = rs("xingming")
xlWorksheet.Cells(2+i,4).Value =rs("xingbie")
xlWorksheet.Cells(2+i,5).Value =rs("chushengriqi")
xlWorksheet.Cells(2+i,6).Value = rs("shouji")
'--------------------------------------------------
response.write rs("xingming")&"<br>"
'response.wirte "ss"&len(rs)&"ss"
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
response.write numberOfColumns;
response.write numberOfColumns&"<br>";
boolean b = rsmd.isSearchable(1);
response.write b

i=i+1
rs.movenext
Loop

Set fs = CreateObject("Scripting.FileSystemObject")
tfile=Server.MapPath("test.xls")
if fs.FileExists(tfile) then
Set f = fs.GetFile(tfile)
f.delete true
Set f = nothing
end if
Set fs = nothing
xlWorksheet.SaveAs tfile '保存文件
xlApplication.Quit '释放对象
Set xlWorksheet = Nothing
Set xlApplication = Nothing
%>
xuyan9927 2007-04-11
  • 打赏
  • 举报
回复
不会吧,真的没人知道吗?
gzapu 2007-04-11
  • 打赏
  • 举报
回复
不会,但帮你顶!
tncboy 2007-04-11
  • 打赏
  • 举报
回复
呵呵,会有人来解决的,帮你顶一下。

asp中应该有现成的com来完成这种操作吧? 这可是MS自已的东西
连java中都有不少组件来存取excel..

关注一下
chouchy 2007-04-11
  • 打赏
  • 举报
回复
1、在一个范围内插入数据
objExcelSheet.Range("B3:k3").Value=Array("1","2","3","4","5","6","7","8","9","10")
2、在一个单元格内插入数据
objExcelSheet.Cells(3,1).Value="InternetExplorer"
xuyan9927 2007-04-11
  • 打赏
  • 举报
回复
没有人回答吗?来的送分

28,408

社区成员

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

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