读取所有数据
注意其中的表名变量 table_name 因为我是从上一个文件接收的 Form 变量,一般情况下第一个表都是 Sheet$,也就是上面的回复那里来的.
<form name="form1" method="post" action="xls_three.asp">
<table width="80%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#666666">
<%
'建立Connection对象
Dim db,rs,strSql,i,rst,table_count,table_name,j,t_all,t_all_two
Set db = Server.CreateObject("ADODB.Connection")
db.Open "Driver={Microsoft Excel Driver (*.xls)};Dbq=" & Server.MapPath("shuju.xls")
'打开记录集,表名一定要以"[表名$]"的格式
table_name = request("table_name")
if table_name = "" then
response.write "<script>alert('对不起,表名不能为空')</script>"
response.write "<script>history.back()</script>"
end if
strSql="Select * From ["&table_name&"]"
Set rs=db.Execute(strSql)
if rs.eof and rs.bof then
response.write "<script>alert('对不起 " &table_name&" 表中没有任何数据')</script>"
response.write "<script>history.back()</script>"
end if
'循环读取所有行
Response.Write "<tr bgcolor = white align='center'>"
Response.Write "<td>操作</td>"
For i = 0 to rs.fields.count - 1
Response.Write "<td>" & rs(i).name & "</td>"
Next
Response.Write "</tr>"
j = 0
Do While Not rs.EOF
Response.Write "<tr bgcolor = white align='center'>"
Response.Write "<td><input type = 'checkbox' name = 'checkbox'/></td>"
For i = 0 to rs.fields.count - 1
Response.Write "<td>" & rs(i) & "</td>"
Next
Response.Write "</tr>"
rs.MoveNext
j = j + 1
Loop
%>
<tr align="center" bgcolor="#E6E6E6">
<td colspan="<%=i + 1%>" align="left" valign="middle" bgcolor="#FFFFFF">您可以选择插入:</td>
</tr>
<tr align="center" bgcolor="#E6E6E6">
<td colspan="<%=i + 1%>" align="center" valign="middle" bgcolor="#FFFFFF"><%
For i = 0 to rs.fields.count - 1
if t_all = "" then
t_all = "<$=" & rs(i).name & "$>"
t_all_two = rs(i).name
else
t_all = t_all & "," & "<$=" & rs(i).name & "$>"
t_all_two = t_all_two & "," & rs(i).name
end if
'Response.Write "<span style='cursor:pointer;color=red' >" &rs(i).name & "</span> "
%>
<span id="wbf" onClick="insertAtCaret(document.form1.tarea,this.innerText);" style="cursor:pointer; color:red
;"><%=rs(i).name%></span>
<%
Next
response.write t_all
%>
<input type="hidden" name="t_all" id="t_all" value="<%=t_all%>">
<input type="hidden" name="t_all_two" id="t_all_two" value="<%=t_all_two%>">
<input type="hidden" name="table_name" id="table_name" value="<%=table_name%>">
</td>
</tr>
<tr align="center" bgcolor="#E6E6E6">
<td colspan="<%=i + 1%>" valign="middle" bgcolor="#FFFFFF">定制发送内容:
<textarea name="tarea" rows="10" cols="80"onselect="setCaret(this);" onClick="setCaret(this);" onKeyUp="setCaret(this);">你好</textarea></td>
</tr>
<tr align="center" bgcolor="#E6E6E6">
<td colspan="<%=i + 1%>"><input type="submit" name="button" id="button" value="提交"> <input type="reset" name="button2" id="button2" value="重置"></td>
</tr>
</table>
</form>
<%
Response.write j
'关闭对象
rs.Close
Set rs=nothing
%>
[[it] 本帖最后由 entermaster 于 2008-6-25 16:56 编辑 [/it]]