asp中导出到CSV
来源:互联网 发布:金鹰220轨道车数据 编辑:程序博客网 时间:2024/04/30 13:58
'==========================================================
'将纪录输出为(.csv)文件
'制作日期:2003年3月
作者 :塞北的雪
'==========================================================
Class Export_CSV
private FSO '文件系统对象
private fExport
dim Exp_Type
private sub Class_Initialize()
set FSO= Server.CreateObject("Scripting.FileSystemObject") '建立文件系统对象实例
Exp_Type=1 '导出类型 1为追加方式写入一个文件 2为新建一个新文件再写入
end sub
'关闭对象
private sub Class_Terminate()
fExport.Close
set FSO=nothing
end sub
'导出主程序(用数组指定字段)
public Function ExportFile(fullpath,rsSet, HeaderArray)
if Exp_type=1 then
if not ExistFile(fullpath) then
if CreateFile(fullpath) then
WriteHeader HeaderArray
WriteBody rsSet,HeaderArray
else
err_Show "创建文件时发生错误!"
end if
else
if OpenFile(fullpath) then
WriteBody rsSet,HeaderArray
else
err_Show "打开文件时发生错误!"
end if
end if
elseif Exp_type=2 then
if ExistFile(fullpath) then
err_Show "文件名冲突!"
else
if CreateFile(fullpath) then
WriteHeader HeaderArray
WriteBody rsSet,HeaderArray
else
err_Show "创建文件时发生错误!"
end if
end if
end if
if err=0 then
ExportFile=true
else
ExportFile=false
end if
end function
'指定的标题书写
public sub WriteHeader( HeaderArray)
sLine = ""
for i=0 to ubound(HeaderArray,2)
sLine=sLine & "," & HeaderArray(0,i)
next
if sLine<>"" then
sLine=right(sLine,len(sLine)-1)
fExport.WriteLine(sLine)
end if
end sub
'记录集指定的字段信息输出
public sub WriteBody(rsSet, HeaderArray)
rsSet.movefirst
Do Until rsSet.EOF
sLine = ""
for i=0 to ubound(HeaderArray,2)
sLine=sLine & "," & rsSet(HeaderArray(1,i))
next
if sLine <> "" then
sLine = right(sLine, Len(sLine)-1)
fExport.WriteLine(sLine)
end if
rsSet.MoveNext
Loop
end sub
'导出主程序(完全记录集)
public Function ExportFile2(fullpath,rsSet)
if Exp_type=1 then
if not ExistFile(fullpath) then
if CreateFile(fullpath) then
WriteHeader2 rsSet
WriteBody2 rsSet
else
err_Show "创建文件时发生错误!"
end if
else
if OpenFile(fullpath) then
WriteBody2 rsSet
else
err_Show "打开文件时发生错误!"
end if
end if
elseif Exp_type=2 then
if ExistFile(fullpath) then
err_Show "文件名冲突!"
else
if CreateFile(fullpath) then
WriteHeader2 rsSet
WriteBody2 rsSet
else
err_Show "创建文件时发生错误!"
end if
end if
end if
if err=0 then
ExportFile2=true
else
ExportFile2=false
end if
end function
'以字段名为标题书写
public sub WriteHeader2(rsSet)
sLine = ""
for i=0 to rsSet.fields.count-1
sLine=sLine & "," & rsSet.fields(i).name
next
if sLine<>"" then
sLine=right(sLine,len(sLine)-1)
fExport.WriteLine(sLine)
end if
end sub
'输出记录集中信息
public sub WriteBody2(rsSet)
rsSet.movefirst
Do Until rsSet.EOF
sLine = ""
for i=0 to rsSet.fields.count-1
sLine=sLine & "," & rsSet.fields(i).value
next
if sLine <> "" then
sLine = right(sLine, Len(sLine)-1)
fExport.WriteLine(sLine)
end if
rsSet.MoveNext
Loop
end sub
'输出错误信息
private sub Err_Show(errDesc)
Response.Write errDesc
Response.End
end sub
'创建一个文件
public Function CreateFile(fullpath)
Set fExport = FSO.CreateTextFile(FullPath, false)
if err=0 then
CreateFile=true
else
CreateFile=false
end if
end function
'打开一个文件
public Function OpenFile(fullpath)
set fExport=FSO.OpenTextFile(fullPath,8,false)
if err=0 then
OpenFile=true
else
OpenFile=false
end if
end function
'判断指定文件名的文件是否存在
public function ExistFile(fullpath)
if FSO.FileExists(fullpath) then
ExistFile=true
else
ExistFile=false
end if
end function
end Class
- asp中导出到CSV
- 导出表中数据到csv
- asp.net中导出到Excel的方法汇总及导出Excel/Csv格式数据最优方案(C#)
- asp.net中导出到Excel的方法汇总及导出Excel/Csv格式数据最优方案(C#)
- asp.net中导出到Excel的方法汇总及导出Excel/Csv格式数据最优方案
- asp.net导出CSV
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- Silverlight的DataGrid中:导出到Excel或CSV 3
- C#导出DataTable数据到CSV文件中
- AD 中所有的用户导出到csv
- asp.net导出csv文件
- asp.net 导出csv,excel
- 导出数据到CSV文件
- mysql导入导出到csv
- 动态HTML教程--关于Event对象(转载)
- 用蓝牙PC共享体验N-gage Arena带来的无穷乐趣
- WindowsCE开发过程
- Zi34116上的多组电话会议系统设计
- Plug-In framework using DLLs
- asp中导出到CSV
- 十年MFC经历认识的Microsoft技术(zz)
- MSN协议中文释义(Zz)
- [JS]“正在处理...”和“进度条”
- CMPP2.0 SP 端开发设计思路
- asp 的DES加密文件
- 正在学习分形
- visual basic.net中的串口通信
- 一生受用的数学公式