asp表格数据导入excel怎么导入

sirfanerbo 2009-03-06 01:55:17
如题 表格里的内容导入excel
...全文
157 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmlwl 2009-03-08
  • 打赏
  • 举报
回复
先把excel文件,另存为htm文件,将此格式保存为文本

其实你就能看到,这是一个表格文件
用ASP读取数据后,写入,最好用FSO写成一个.xls文件
最后一个转向就OK
春天的气息 2009-03-08
  • 打赏
  • 举报
回复
asp导好麻烦呀,还不如用asp.net吧!

欢迎加入我的程序设计QQ群80532706哟
sirfanerbo 2009-03-06
  • 打赏
  • 举报
回复
我现在导出的数据一种就是说css丢失 都乱了 一种就是查询和表格数据在不同页面 可以导出 但是那样的话不美观 而且只能导出一页的数据 有什么好的解决方法???各位 help
sirfanerbo 2009-03-06
  • 打赏
  • 举报
回复
<script language="javascript">
function tableToExcel() {
window.clipboardData.setData("Text",document.all('theObjTable').outerHTML);
try
{
var ExApp = new ActiveXObject("Excel.Application")
var ExWBk = ExApp.workbooks.add()
var ExWSh = ExWBk.worksheets(1)
ExApp.DisplayAlerts = false
ExApp.visible = true
}
catch(e)
{
alert("您的电脑没有安装Microsoft Excel软件!")
return false
}
ExWBk.worksheets(1).Paste;
}
</script>
怎么老是没安装Microsoft Excel软件啊
sirfanerbo 2009-03-06
  • 打赏
  • 举报
回复
1楼的效率差了吧 我网页打都打不开了
wansai00 2009-03-06
  • 打赏
  • 举报
回复
有个最简单的办法

把table的内容处理成逗号分隔符excel的形式
内容,内容(换行)
内容,内容(换行)

举个例子 用replace替换的方法
excel = table
excel = replace(table, chr(10), "")
excel = replace(table, chr(13), "")
excel = replace(table, "<tr><td>", "")
excel = replace(table, "</td><td>", ",")
excel = replace(table, "</tr>", chr(10))
正则也可以

最后把excel字符串存到文本文件里 后缀名用"*.csv"
hongmaohouzi 2009-03-06
  • 打赏
  • 举报
回复
用asp将access中的数据导入到excel文件中,源代码如下:

<%
server.scripttimeout=100000 '处理时间较长,设置值应大一点
on error resume next
set objexcelapp = createobject("excel.application")
objexcelapp.displayalerts = false
objexcelapp.application.visible = false
objexcelapp.workbooks.add
set objexcelbook = objexcelapp.activeworkbook
set objexcelsheets = objexcelbook.worksheets
set objspreadsheet = objexcelbook.sheets(1)
dim conn
dim connstr
dim db
db="weste.mdb" '这里选择数据库
set conn = server.createobject("adodb.connection")
connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
conn.open connstr
dim objrs
set objrs = server.createobject("adodb.recordset")
objrs.open "select * from friendlink",conn,1,3 '这里用sql语句查询需要导出的内容
if objrs.eof then
response.write("error")
respose.end
end if

dim objfield, icol, irow
icol = 1 '取得列号
irow = 1 '取得行号
objspreadsheet.cells(irow, icol).value = "用asp将access中的数据导入到excel文件——西部e网" '单元格插入数据
objspreadsheet.columns(icol).shrinktofit=true '设定是否自动适应表格单元大小(单元格宽不变)
'设置excel表里的字体
objspreadsheet.cells(irow, icol).font.bold = true '单元格字体加粗
objspreadsheet.cells(irow, icol).font.italic = false '单元格字体倾斜
objspreadsheet.cells(irow, icol).font.size = 20 '设置单元格字号
objspreadsheet.cells(irow, icol).paragraphformat.alignment=1 '设置单元格对齐格式:居中
objspreadsheet.cells(irow,icol).font.name="宋体" '设置单元格字体
objspreadsheet.cells(irow,icol).font.colorindex=2 '设置单元格文字的颜色,颜色可以查询,2为白色
objspreadsheet.range("a1:f1").merge '合并单元格(单元区域)
objspreadsheet.range("a1:f1").interior.colorindex = 1 '设计单元络背景色
'objspreadsheet.range("a2:f2").wraptext=true '设置字符回卷(自动换行)
irow=irow+1
for each objfield in objrs.fields
'objspreadsheet.columns(icol).shrinktofit=true
objspreadsheet.cells(irow, icol).value = objfield.name
'设置excel表里的字体
objspreadsheet.cells(irow, icol).font.bold = true
objspreadsheet.cells(irow, icol).font.italic = false
objspreadsheet.cells(irow, icol).font.size = 20
objspreadsheet.cells(irow, icol).halignment = 2 '居中
icol = icol + 1
next 'objfield
'display all of the data
do while not objrs.eof
irow = irow + 1
icol = 1
for each objfield in objrs.fields
if isnull(objfield.value) then
objspreadsheet.cells(irow, icol).value = ""
else
objspreadsheet.columns(icol).shrinktofit=true
objspreadsheet.cells(irow, icol).value = objfield.value
objspreadsheet.cells(irow, icol).halignment = 2
objspreadsheet.cells(irow, icol).font.bold = false
objspreadsheet.cells(irow, icol).font.italic = false
objspreadsheet.cells(irow, icol).font.size = 10
'objspreadsheet.cells(irow, icol).halignment = 2

end if
icol = icol + 1
next 'objfield
objrs.movenext
loop

dim savename
savename="temp1"
dim objexcel
dim excelpath
excelpath = "" & savename & ".xls"
objexcelbook.saveas server.mappath(excelpath)
response.write("<a href='" & server.urlencode(excelpath) & "'>下载</a>")
objexcelapp.quit
set objexcelapp = nothing
%>

把上面数据库中读取的这些数据,换成表格里的数据!

28,390

社区成员

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

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