电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Asp>>asp生成excel文件:

asp生成excel文件

来源:www.cncfan.com | 2006-8-9 | (有3074人读过)

<!--#i nclude FILE="../conn.inc" -->
<%
Set rs= Server.CreateObject("ADODB.Recordset")
sql="select wpbh,wplb,wpmc,ggxh,jldw from wpjbxx"
rs.open sql,conn,1,1
'response.write sql
'response.end
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>asp生成excel文件</title>
</head>
<body>
<%
CreateXlsFile()
%>
</body>
</html>
<script LANGUAGE=vbscript RUNAT=Server>
Function GenFileName()
dim fname

fname = "File"
systime=now()
fname= fname & cstr(year(systime)) & cstr(month(systime)) & cstr(day(systime))
fname= fname & cstr(hour(systime)) & cstr(minute(systime)) & cstr(second(systime))
GenFileName = fname
End Function

Function CreateXlsFile()
Dim xlWorkSheet ' Excel Worksheet object
Dim xlApplication
//如提示CreateObject("Excel.application")没有权限
//则运行(dcomcnfg)或在管理工具中运行组件服务--计算机--DCOM配置--Micorsoft Excel应用程序
///右键属性--把安全选项中的启动和激活权限附给everyone
Set xlApplication = CreateObject("Excel.application") '调用excel对象
'xlApplication.Visible = false
xlApplication.DisplayAlerts = false //不显示警告
xlApplication.Application.Visible = false //不显示界面
xlApplication.Workbooks.Add
Set xlWorksheet = xlApplication.Worksheets(1)
xlWorksheet.Cells(1,1).Value = "物品基本信息"
iRow = 2
xlWorksheet.Cells(2,1).Value = "物品编码"
xlWorksheet.Cells(2,2).Value = "物品类别"
xlWorksheet.Cells(2,3).Value = "物品名称"
xlWorksheet.Cells(2,4).Value = "规格型号"
xlWorksheet.Cells(2,5).Value = "计量单位"
iRow = 3
If Not rs.EOF Then
Do Until rs.EOF
For i = 0 To rs.fields.Count-1
xlWorksheet.Cells(iRow,i + 1).Value = rs.fields(i)
//xlWorksheet.Cells(iRow,i + 1).HorizontalAlignment = xlCenter
//xlWorksheet.Cells(iRow,i + 1).VerticalAlignment = xlCenter
Next
iRow = iRow + 1
rs.MoveNext
Loop
End If
strFile = GenFileName()
xlWorksheet.SaveAs Server.MapPath(".") & "\" & strFile & ".xls"
xlApplication.Quit ' Close the Workbook
Set xlWorksheet = Nothing
Set xlApplication = Nothing
Response.Write("Click <A HRef=" & strFile & ".xls>Here</A> to get XLS file")
End Function
</script>
<script language="javascript">
function exportExcel(atblData)
{
if(typeof(EXPORT_OBJECT)!="object")
{
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid=clsid:0002E510-0000-0000-C000-000000000046 id=EXPORT_OBJECT></Object>");
}
with (EXPORT_OBJECT)
{
DataType = "HTMLData";
HTMLData =atblData.outerHTML;
try{
ActiveSheet.Export("C:\\owcToExcel.xls", 0);
alert('汇出完毕');
}
catch (e){
alert('汇出Excel表失败,请确定已安装Excel2000(或更高版本),并且没打开同名xls文件');
}
}
}
</script>

Asp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号