我们有时候需要把数据导出来,作为参考等等。下面就为你介绍,ASP 导出Excel书籍的四种方法。
一、使用OWC
什么是OWC?
OWC是office Web Compent的缩写,即Microsoft的office Web组件,它为在Web中绘制图形提供了灵活的同时也是最基本的机制。在一个intranet环境中,如果可以假设客户机上存在特定的浏览器和一些功能强大的软件(如IE5和office 2000),那么就有能力利用office Web组件提供一个交互式图形开发环境。这种模式下,客户端工作站将在整个任务中分担很大的比重。
以下为引用的内容:
<%Option Explicit
Class ExcelGen
Private obJSPreadsheet
Private iColOffset
Private iRowOffset
Sub Class_Initialize()
Set obJSPreadsheet = Server.CreateObject("OWC.Spreadsheet")
iRowOffset = 2
iColOffset = 2
End Sub
Sub Class_Terminate()
Set obJSPreadsheet = Nothing 'Clean up
End Sub
Public Property Let ColumnOffset(iColOff)
If iColOff > 0 then
iColOffiColOffset = iColOff
Else
iColOffset = 2
End If
End Property
Public Property Let RowOffset(iRowOff)
If iRowOff > 0 then
iRowOffiRowOffset = iRowOff
Else
iRowOffset = 2
End If
End Property Sub GenerateWorksheet(objRS)
'Populates the Excel worksheet based on a Recordset's contents
'Start by displaying the titles
If objRS.EOF then Exit Sub
Dim objField, iCol, iRow
iCol = iColOffset
iRow = iRowOffset
For Each objField in objRS.Fields
obJSPreadsheet.Cells(iRow, iCol).Value = objField.Name
obJSPreadsheet.Columns(iCol).AutoFitColumns
'设置Excel表里的字体
obJSPreadsheet.Cells(iRow, iCol).Font.Bold = True
obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False
obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10
obJSPreadsheet.Cells(iRow, iCol).Halignment = 2 '居中
iColiCol = iCol + 1
Next 'objField
'Display all of the data
Do While Not objRS.EOF
iRowiRow = iRow + 1
iCol = iColOffset
For Each objField in objRS.Fields
If IsNull(objField.Value) then
obJSPreadsheet.Cells(iRow, iCol).Value = ""
Else
obJSPreadsheet.Cells(iRow, iCol).Value = objField.Value
obJSPreadsheet.Columns(iCol).AutoFitColumns
obJSPreadsheet.Cells(iRow, iCol).Font.Bold = False
obJSPreadsheet.Cells(iRow, iCol).Font.Italic = False
obJSPreadsheet.Cells(iRow, iCol).Font.Size = 10
End If
iColiCol = iCol + 1
Next 'objField
objRS.MoveNext
Loop
End Sub Function SaveWorksheet(strFileName)
'Save the worksheet to a specified filename
On Error Resume Next
Call obJSPreadsheet.ActiveSheet.Export(strFileName, 0)
SaveWorksheet = (Err.Number = 0)
End Function
End Class
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM xxxx", "Provider=SQLOLEDB.1;Persist Security
Info=True;User ID=xxxx;Password=xxxx;Initial Catalog=xxxx;Data source=xxxx;"
Dim SaveName
SaveName = Request.Cookies("savename")("name")
Dim objExcel
Dim ExcelPath
ExcelPath = "Excel\" & SaveName & ".xls"
Set objExcel = New ExcelGen
objExcel.RowOffset = 1
objExcel.ColumnOffset = 1
objExcel.GenerateWorksheet(objRS)
If objExcel.SaveWorksheet(Server.MapPath(ExcelPath)) then
'Response.Write "已保存为Excel文件.
下载 "
Else
Response.Write "在保存过程中有错误!"
End If
Set objExcel = Nothing
objRS.Close
Set objRS = Nothing
%>
二、用Excel的Application组件在客户端导出到Excel或word
以下为引用的内容:
注意:两个函数中的“data“是网页中要导出的table的 id
导出到Excel代码
导出到word代码
三、直接在IE中打开,再存为Excel文件
以下为引用的内容:
把读出的数据用
格式,在网页中显示出来,同时,加上下一句即可把Excel表在客客户端显示。<%response.ContentType ="application/vnd.ms-Excel"%>
注意:显示的页面中,只把
输出,***不要输出其他表格以外的信息。四、导出以半角逗号隔开的csv
用fso方法生成文本文件的方法,生成一个扩展名为csv文件。此文件,一行即为数据表的一行。生成数据表字段用半角逗号隔开。(有关fso生成文本文件的方法,在此就不做介绍了)
CSV文件介绍 (逗号分隔文件)
选择该项系统将创建一个可供下载的CSV 文件; CSV是最通用的一种文件格式,它可以非常容易地被导入各种PC表格及数据库中。
请注意即使选择表格作为输出格式,仍然可以将结果下载CSV文件。在表格输出屏幕的底部,显示有 "CSV 文件"选项,点击它即可下载该文件。
希望本文介绍的三种方法,能够帮助到你。
网站栏目:ASP教程之导出Excel数据的四种方法
本文URL:http://jxjierui.cn/article/dhcihes.html
基本
文件
流程
错误
SQL
调试
请求信息 : 2026-02-16 17:48:22 HTTP/1.1 GET : /article/dhcihes.html 运行时间 : 0.0698s ( Load:0.0033s Init:0.0005s Exec:0.0616s Template:0.0044s ) 吞吐率 : 14.33req/s 内存开销 : 2,240.17 kb 查询信息 : 12 queries 5 writes 文件加载 : 36 缓存信息 : 0 gets 2 writes 配置加载 : 130 会话信息 : SESSION_ID=694o3q84gvbdlc4ej74jed4152
/home/wwwroot/jxjierui.cn/index.php ( 1.12 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/ThinkPHP.php ( 4.61 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Mode/common.php ( 2.82 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Common/functions.php ( 53.56 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/App.class.php ( 13.49 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/View.class.php ( 7.59 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Conf/convention.php ( 11.15 KB ) /home/wwwroot/jxjierui.cn/App/Common/Conf/config.php ( 2.12 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Lang/zh-cn.php ( 2.55 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Conf/debug.php ( 1.48 KB ) /home/wwwroot/jxjierui.cn/App/Home/Conf/config.php ( 0.32 KB ) /home/wwwroot/jxjierui.cn/App/Home/Common/function.php ( 3.33 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB ) /home/wwwroot/jxjierui.cn/App/Home/Controller/ArticleController.class.php ( 6.11 KB ) /home/wwwroot/jxjierui.cn/App/Home/Controller/CommController.class.php ( 1.60 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB ) /home/wwwroot/jxjierui.cn/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 13.96 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB ) /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
[ app_init ] --START-- Run Behavior\BuildLiteBehavior [ RunTime:0.000004s ] [ app_init ] --END-- [ RunTime:0.000023s ] [ app_begin ] --START-- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000150s ] [ app_begin ] --END-- [ RunTime:0.000166s ] [ view_parse ] --START-- [ template_filter ] --START-- Run Behavior\ContentReplaceBehavior [ RunTime:0.000051s ] [ template_filter ] --END-- [ RunTime:0.000068s ] Run Behavior\ParseTemplateBehavior [ RunTime:0.003506s ] [ view_parse ] --END-- [ RunTime:0.003527s ] [ view_filter ] --START-- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000077s ] [ view_filter ] --END-- [ RunTime:0.000088s ] [ app_end ] --START--
1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= ) [8] Undefined index: pid /home/wwwroot/jxjierui.cn/App/Home/Controller/ArticleController.class.php 第 47 行. [2] file_put_contents(./App/Runtime/Temp/42204a416feb12b218a5cc9df41f7817.php): failed to open stream: Permission denied /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 132 行. [8] Undefined index: db_host /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 120 行. [8] Undefined index: db_port /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 121 行. [8] Undefined index: db_name /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 122 行. [2] file_put_contents(./App/Runtime/Temp/4116d4427bb6030e5687dfa3c0e5da34.php): failed to open stream: Permission denied /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 132 行.
0.0698s