代碼如下:
<%
'*******************************************************************
'使用說明
'Dim a
'Set a=new CreateExcel
'a.SavePath="x" '保存路徑
'a.SheetName="工作簿名稱" '多個工作表 a.SheetName=array("工作簿名稱一","工作簿名稱二")
'a.SheetTitle="表名稱" '可以為空 多個工作表 a.SheetName=array("表名稱一","表名稱二")
'a.Data =d '二維數組 '多個工作表 array(b,c) b與c為二維數組
'Dim rs
'Set rs=server.CreateObject("Adodb.RecordSet")
'rs.open "Select id, classid, className from [class] ",conn, 1, 1
'a.AddDBData rs, "字段名一,字段名二", "工作簿名稱", "表名稱", true 'true自動獲取表字段名
'a.AddData c, true , "工作簿名稱", "表名稱" 'c二維數組 true 第一行是否為標題行
'a.AddtData e, "Sheet1" '按模板生成 c=array(array("AA1", "內容"), array("AA2", "內容2"))
'a.Create()
'a.UsedTime 生成時間,毫秒數
'a.SavePath 保存路徑
'Set a=nothing
'設置COM組件的操作權限。在命令行鍵入“DCOMCNFG”,則進入COM組件配置界面,選擇MicrosoftExcel後點擊屬性按鈕,將三個單選項一律選擇自定義,編輯中將Everyone加入所有權限
'*******************************************************************
Class CreateExcel
Private CreateType_
Private savePath_
Private readPath_
Private AuthorStr Rem 設置作者
Private VersionStr Rem 設置版本
Private SystemStr Rem 設置系統名稱
Private SheetName_ Rem 設置表名
Private SheetTitle_ Rem 設置標題
Private ExcelData Rem 設置表數據
Private ExcelApp Rem Excel.Application
Private ExcelBook
Private ExcelSheets
Private UsedTime_ Rem 使用的時間
Public TitleFirstLine Rem 首行是否標題
Private Sub Class_Initialize()
Server.ScriptTimeOut = 99999
UsedTime_ = Timer
SystemStr = "Lc00_CreateExcelServer"
AuthorStr = "Surnfu [email protected] 31333716"
VersionStr = "1.0"
if not IsObjInstalled("Excel.Application") then
InErr("服務器未安裝Excel.Application控件")
end if
set ExcelApp = createObject("Excel.Application")
ExcelApp.DisplayAlerts = false
ExcelApp.Application.Visible = false
CreateType_ = 1
readPath_ = null
End SubPrivate Sub Class_Terminate()
ExcelApp.Quit
If Isobject(ExcelSheets) Then Set ExcelSheets = Nothing
If Isobject(ExcelBook) Then Set ExcelBook = Nothing
If Isobject(ExcelApp) Then Set ExcelApp = Nothing
End SubPublic Property Let ReadPath(ByVal Val)
If Instr(Val, ":")<>0 Then
readPath_ = Trim(Val)
else
readPath_=Server.MapPath(Trim(Val))
end if
End PropertyPublic Property Let SavePath(ByVal Val)
If Instr(Val, ":")<>0 Then
savePath_ = Trim(Val)
else
savePath_=Server.MapPath(Trim(Val))
end if
End Property
Public Property Let CreateType(ByVal Val)
if Val <> 1 and Val <> 2 then
CreateType_ = 1
else
CreateType_ = Val
end if
End Property
Public Property Let Data(ByVal Val)
if not isArray(Val) then
InErr("表數據設置有誤")