最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

asp操作Excel类技巧

日期:06-20    来源:网页设计秀    作者:cnwebshow.com

程序代码n7U中国设计秀
<%n7U中国设计秀
'***************************************************************************************n7U中国设计秀
'使用说明n7U中国设计秀
'Dim an7U中国设计秀
'Set a=new Createexceln7U中国设计秀
'a.SavePath="x" '保存路径n7U中国设计秀
'a.SheetName="工作簿名称"       '多个工作表 a.SheetName=array("工作簿名称一","工作簿名称二")n7U中国设计秀
'a.SheetTitle="表名称"         '可以为空  多个工作表 a.SheetName=array("表名称一","表名称二")n7U中国设计秀
'a.Data =d '二维数组             '多个工作表 array(b,c) b与c为二维数组n7U中国设计秀
'Dim rsn7U中国设计秀
'Set rs=server.CreateObject("Adodb.RecordSet")n7U中国设计秀
'rs.open "Select id, classid, className from [class] ",conn, 1, 1n7U中国设计秀
'a.AddDBData rs, "字段名一,字段名二", "工作簿名称", "表名称",     true    'true自动获取表字段名n7U中国设计秀
'a.AddData c, true , "工作簿名称", "表名称"    'c二维数组          true  第一行是否为标题行n7U中国设计秀
'a.AddtData e, "Sheet1"   '按模板生成  c=array(array("AA1", "内容"), array("AA2", "内容2"))n7U中国设计秀
'a.Create()n7U中国设计秀
'a.UsedTime        生成时间,毫秒数n7U中国设计秀
'a.SavePath        保存路径n7U中国设计秀
'Set a=nothingn7U中国设计秀
'设置COM组件的操作权限。在命令行键入“DCOMCNFG”,则进入COM组件配置界面,选择Microsoftexcel后点击属性按钮,将三个单选项一律选择自定义,编辑中将Everyone加入所有权限n7U中国设计秀
'****************************************************************************************n7U中国设计秀
Class Createexcel n7U中国设计秀
    PRivate CreateType_n7U中国设计秀
    Private savePath_n7U中国设计秀
    Private readPath_n7U中国设计秀
    Private AuthorStr              Rem 设置作者n7U中国设计秀
    Private VersionStr          Rem 设置版本n7U中国设计秀
    Private SystemStr              Rem 设置系统名称n7U中国设计秀
    Private SheetName_             Rem 设置表名n7U中国设计秀
    Private SheetTitle_         Rem 设置标题n7U中国设计秀
    Private excelData             Rem 设置表数据n7U中国设计秀
    Private excelApp             Rem excel.applicationn7U中国设计秀
    Private excelBookn7U中国设计秀
    Private excelSheetsn7U中国设计秀
    Private UsedTime_            Rem 使用的时间n7U中国设计秀
    Public TitleFirstLine        Rem 首行是否标题n7U中国设计秀
    Private Sub Class_Initialize()n7U中国设计秀
        Server.ScriptTimeOut = 99999n7U中国设计秀
        UsedTime_ = Timern7U中国设计秀
        SystemStr            =    "Lc00_CreateexcelServer"n7U中国设计秀
        AuthorStr            =    "Surnfu  surnfu@126.com  31333716"n7U中国设计秀
        VersionStr            =    "1.0"n7U中国设计秀
        if not IsObjInstalled("excel.Application") thenn7U中国设计秀
            InErr("服务器未安装excel.Application控件")n7U中国设计秀
        end ifn7U中国设计秀
        set excelApp = createObject("excel.Application")n7U中国设计秀
        excelApp.DisplayAlerts = falsen7U中国设计秀
        excelApp.Application.Visible = falsen7U中国设计秀
        CreateType_ = 1n7U中国设计秀
        readPath_ = nulln7U中国设计秀
    End Subn7U中国设计秀

    Private Sub Class_Terminate()n7U中国设计秀
        excelApp.Quitn7U中国设计秀
        If Isobject(excelSheets)     Then Set excelSheets    =    Nothingn7U中国设计秀
        If Isobject(excelBook)         Then Set excelBook        =    Nothingn7U中国设计秀
        If Isobject(excelApp)         Then Set excelApp        =    Nothingn7U中国设计秀
    End Subn7U中国设计秀

    Public Property Let ReadPath(ByVal Val)n7U中国设计秀
        If Instr(Val, ":")<>0 Thenn7U中国设计秀
            readPath_ = Trim(Val)n7U中国设计秀
        elsen7U中国设计秀
            readPath_=Server.MapPath(Trim(Val))n7U中国设计秀
        end ifn7U中国设计秀
    End Propertyn7U中国设计秀

    Public Property Let SavePath(ByVal Val)n7U中国设计秀
        If Instr(Val, ":")<>0 Thenn7U中国设计秀
            savePath_ = Trim(Val)n7U中国设计秀
        elsen7U中国设计秀
            savePath_=Server.MapPath(Trim(Val))n7U中国设计秀
        end ifn7U中国设计秀
    End Propertyn7U中国设计秀
    n7U中国设计秀
    n7U中国设计秀
    Public Property Let CreateType(ByVal Val)n7U中国设计秀
        if Val <> 1 and Val <> 2 thenn7U中国设计秀
            CreateType_ = 1n7U中国设计秀
        elsen7U中国设计秀
            CreateType_ = Valn7U中国设计秀
        end if    n7U中国设计秀
    End Propertyn7U中国设计秀
    n7U中国设计秀
    Public Property Let Data(ByVal Val)n7U中国设计秀
        if not isArray(Val) thenn7U中国设计秀
            InErr("表数据设置有误")n7U中国设计秀
        end ifn7U中国设计秀
          excelData = Valn7U中国设计秀
    End Propertyn7U中国设计秀
    Public Property Get SavePath()n7U中国设计秀
    SavePath = savePath_n7U中国设计秀
    End Propertyn7U中国设计秀
    Public Property Get UsedTime()n7U中国设计秀
          UsedTime = UsedTime_n7U中国设计秀
    End Propertyn7U中国设计秀
    Public Property Let SheetName(ByVal Val)n7U中国设计秀
        if not isArray(Val) thenn7U中国设计秀
            if Val = "" thenn7U中国设计秀
                InErr("表名设置有误")n7U中国设计秀
            end ifn7U中国设计秀
            TitleFirstLine = truen7U中国设计秀
        elsen7U中国设计秀
            ReDim TitleFirstLine(Ubound(Val))n7U中国设计秀
            Dim ik_n7U中国设计秀
            For ik_ = 0 to Ubound(Val)n7U中国设计秀
                TitleFirstLine(ik_) = truen7U中国设计秀
            Nextn7U中国设计秀
        end ifn7U中国设计秀
          SheetName_ = Valn7U中国设计秀
    End Propertyn7U中国设计秀
    n7U中国设计秀
    Public Property Let SheetTitle(ByVal Val)n7U中国设计秀
        if not isArray(Val) thenn7U中国设计秀
            if Val = "" thenn7U中国设计秀
                InErr("表标题设置有误")n7U中国设计秀
            end ifn7U中国设计秀
        end ifn7U中国设计秀
          SheetTitle_ = Valn7U中国设计秀
    End Propertyn7U中国设计秀
    n7U中国设计秀
    Rem 检查数据n7U中国设计秀
    Private Sub CheckData()n7U中国设计秀
        if savePath_ = "" then InErr("保存路径不能为空")n7U中国设计秀
        if not isArray(SheetName_) thenn7U中国设计秀
            if SheetName_ = "" then InErr("表名不能为空")n7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        if CreateType_ = 2 thenn7U中国设计秀
            if not isArray(excelData) thenn7U中国设计秀
                InErr("数据载入错误,或者未载入")n7U中国设计秀
            end ifn7U中国设计秀
            Exit Subn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        if isArray(SheetName_) thenn7U中国设计秀
            if not isArray(SheetTitle_) thenn7U中国设计秀
                if SheetTitle_ <> "" then InErr("表标题设置有误,与表名不对应")n7U中国设计秀
            end ifn7U中国设计秀
        end ifn7U中国设计秀
        if not IsArray(excelData) thenn7U中国设计秀
            InErr("表数据载入有误")n7U中国设计秀
        end ifn7U中国设计秀
        if isArray(SheetName_) thenn7U中国设计秀
            if GetArrayDim(excelData) <> 1 then InErr("表数据载入有误,数据格式错误,维度应该为一")n7U中国设计秀
        elsen7U中国设计秀
            if GetArrayDim(excelData) <> 2 then InErr("表数据载入有误,数据格式错误,维度应该为二")n7U中国设计秀
        end ifn7U中国设计秀
    End Subn7U中国设计秀
    Rem 生成exceln7U中国设计秀
    Public Function Create()n7U中国设计秀
        Call CheckData()n7U中国设计秀
        if not isnull(readPath_) thenn7U中国设计秀
            excelApp.WorkBooks.Open(readPath_) n7U中国设计秀
        elsen7U中国设计秀
            excelApp.WorkBooks.addn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        set excelBook = excelApp.ActiveWorkBookn7U中国设计秀
        set excelSheets = excelBook.Worksheetsn7U中国设计秀
        n7U中国设计秀
        if CreateType_ = 2 thenn7U中国设计秀
            Dim ih_n7U中国设计秀
            For ih_ = 0 to Ubound(excelData)n7U中国设计秀
                Call SetSheets(excelData(ih_), ih_)n7U中国设计秀
            Nextn7U中国设计秀
            excelBook.SaveAs savePath_n7U中国设计秀
            UsedTime_ = FormatNumber((Timer - UsedTime_)*1000, 3)n7U中国设计秀
            Exit Functionn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        if IsArray(SheetName_) thenn7U中国设计秀
            Dim ik_n7U中国设计秀
            For ik_ = 0 to Ubound(excelData)n7U中国设计秀
                Call CreateSheets(excelData(ik_), ik_)n7U中国设计秀
            Nextn7U中国设计秀
        elsen7U中国设计秀
            Call CreateSheets(excelData, -1)n7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        excelBook.SaveAs savePath_n7U中国设计秀
        UsedTime_ = FormatNumber((Timer - UsedTime_)*1000, 3)n7U中国设计秀
    End Function n7U中国设计秀
    Private Sub CreateSheets(ByVal Data_, DataId_)n7U中国设计秀
        Dim Spreadsheetn7U中国设计秀
        Dim tempSheetTitlen7U中国设计秀
        Dim tempTitleFirstLinen7U中国设计秀
        if DataId_<>-1 thenn7U中国设计秀
            if DataId_ > excelSheets.Count - 1 thenn7U中国设计秀
                excelSheets.Add()n7U中国设计秀
                set Spreadsheet = excelBook.Sheets(1)n7U中国设计秀
            elsen7U中国设计秀
                set Spreadsheet = excelBook.Sheets(DataId_ + 1)n7U中国设计秀
            end ifn7U中国设计秀
            if isArray(SheetTitle_) thenn7U中国设计秀
                tempSheetTitle = SheetTitle_(DataId_)n7U中国设计秀
            elsen7U中国设计秀
                tempSheetTitle = ""n7U中国设计秀
            end ifn7U中国设计秀
            tempTitleFirstLine = TitleFirstLine(DataId_)n7U中国设计秀
            Spreadsheet.Name = SheetName_(DataId_)n7U中国设计秀
        elsen7U中国设计秀
            set Spreadsheet = excelBook.Sheets(1)n7U中国设计秀
            Spreadsheet.Name = SheetName_n7U中国设计秀
            tempSheetTitle = SheetTitle_n7U中国设计秀
            tempTitleFirstLine = TitleFirstLinen7U中国设计秀
        end ifn7U中国设计秀
        Dim Line_ : Line_ = 1n7U中国设计秀
        Dim RowNum_ : RowNum_ = Ubound(Data_, 1) + 1n7U中国设计秀
        Dim LastCols_n7U中国设计秀
        if tempSheetTitle <> "" thenn7U中国设计秀
            'Spreadsheet.Columns(1).ShrinkToFit=true '设定是否自动适应表格单元大小(单元格宽不变)n7U中国设计秀
            LastCols_ = getColName(Ubound(Data_, 2) + 1)n7U中国设计秀
            with Spreadsheet.Cells(1, 1)n7U中国设计秀
                .value = tempSheetTitlen7U中国设计秀
                '设置excel表里的字体 n7U中国设计秀
                .Font.Bold = True '单元格字体加粗n7U中国设计秀
                .Font.Italic = False '单元格字体倾斜n7U中国设计秀
                .Font.Size = 20 '设置单元格字号n7U中国设计秀
                .font.name="宋体" '设置单元格字体n7U中国设计秀
                '.font.ColorIndex=2 '设置单元格文字的颜色,颜色可以查询,2为白色n7U中国设计秀
            End withn7U中国设计秀
            with Spreadsheet.Range("A1:"& LastCols_ &"1")n7U中国设计秀
                .merge '合并单元格(单元区域)n7U中国设计秀
                '.Interior.ColorIndex = 1 '设计单元络背景色n7U中国设计秀
                .HorizontalAlignment = 3 '居中n7U中国设计秀
            End withn7U中国设计秀
            Line_ = 2n7U中国设计秀
            RowNum_ = RowNum_ + 1n7U中国设计秀
        end ifn7U中国设计秀
        Dim iRow_, iCol_n7U中国设计秀
        Dim dRow_, dCol_n7U中国设计秀
        Dim tempLastRange : tempLastRange = getColName(Ubound(Data_, 2)+1) & (RowNum_)n7U中国设计秀
        n7U中国设计秀
        Dim BeginRow : BeginRow = 1n7U中国设计秀
        if tempSheetTitle <> "" then BeginRow = BeginRow + 1n7U中国设计秀
        if tempTitleFirstLine = true then BeginRow = BeginRow + 1n7U中国设计秀
        'http://www.devdao.com/n7U中国设计秀
        if BeginRow=1 thenn7U中国设计秀
            with Spreadsheet.Range("A1:"& tempLastRange)n7U中国设计秀
                .Borders.LineStyle = 1n7U中国设计秀
                .BorderAround -4119, -4138 '设置外框n7U中国设计秀
                .NumberFormatLocal = "@"   '文本格式n7U中国设计秀
                .Font.Bold = False n7U中国设计秀
                .Font.Italic = False n7U中国设计秀
                .Font.Size = 10n7U中国设计秀
                .ShrinkToFit=true n7U中国设计秀
            end withn7U中国设计秀
        elsen7U中国设计秀
            with Spreadsheet.Range("A1:"& tempLastRange)n7U中国设计秀
                .Borders.LineStyle = 1n7U中国设计秀
                .BorderAround -4119, -4138n7U中国设计秀
                .ShrinkToFit=true n7U中国设计秀
            end withn7U中国设计秀
            n7U中国设计秀
            with Spreadsheet.Range("A"& BeginRow &":"& tempLastRange)n7U中国设计秀
                .NumberFormatLocal = "@" n7U中国设计秀
                .Font.Bold = False n7U中国设计秀
                .Font.Italic = False n7U中国设计秀
                .Font.Size = 10n7U中国设计秀
            end withn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        if tempTitleFirstLine = true thenn7U中国设计秀
            BeginRow = 1n7U中国设计秀
            if tempSheetTitle <> "" then BeginRow = BeginRow + 1n7U中国设计秀
        n7U中国设计秀
            with Spreadsheet.Range("A"& BeginRow &":"& getColName(Ubound(Data_, 2)+1) & (BeginRow))n7U中国设计秀
                .NumberFormatLocal = "@"n7U中国设计秀
                .Font.Bold = True n7U中国设计秀
                .Font.Italic = False n7U中国设计秀
                .Font.Size = 12n7U中国设计秀
                .Interior.ColorIndex = 37n7U中国设计秀
                .HorizontalAlignment = 3 '居中n7U中国设计秀
                .font.ColorIndex=2n7U中国设计秀
            end withn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        For iRow_ = Line_ To RowNum_n7U中国设计秀
            For iCol_ = 1 To (Ubound(Data_, 2) + 1)n7U中国设计秀
                dCol_ = iCol_ - 1n7U中国设计秀
                if tempSheetTitle <> "" then dRow_ = iRow_ - 2 else dRow_ = iRow_ - 1n7U中国设计秀
                If not IsNull(Data_(dRow_, dCol_)) then n7U中国设计秀
                    with Spreadsheet.Cells(iRow_, iCol_)n7U中国设计秀
                        .Value = Data_(dRow_, dCol_)n7U中国设计秀
                    End withn7U中国设计秀
                End If n7U中国设计秀
            Nextn7U中国设计秀
        Nextn7U中国设计秀
        set Spreadsheet = Nothingn7U中国设计秀
    End Sub n7U中国设计秀
    Rem 测试组件是否已经安装n7U中国设计秀
    Private Function IsObjInstalled(strClassString)n7U中国设计秀
        On Error Resume Nextn7U中国设计秀
        IsObjInstalled = Falsen7U中国设计秀
        Err = 0n7U中国设计秀
        Dim xTestObjn7U中国设计秀
        Set xTestObj = Server.CreateObject(strClassString)n7U中国设计秀
        If 0 = Err Then IsObjInstalled = Truen7U中国设计秀
        Set xTestObj = Nothingn7U中国设计秀
        Err = 0n7U中国设计秀
    End Functionn7U中国设计秀
    Rem 取得数组维数n7U中国设计秀
    Private Function GetArrayDim(ByVal arr)   n7U中国设计秀
        GetArrayDim = Null   n7U中国设计秀
        Dim i_, temp   n7U中国设计秀
        If IsArray(arr) Then  n7U中国设计秀
            For i_ = 1 To 60   n7U中国设计秀
                On Error Resume Next  n7U中国设计秀
                temp = UBound(arr, i_)   n7U中国设计秀
                If Err.Number <> 0 Then  n7U中国设计秀
                    GetArrayDim = i_ - 1n7U中国设计秀
                    Err.Clear n7U中国设计秀
                    Exit Function  n7U中国设计秀
                End If  n7U中国设计秀
            Next  n7U中国设计秀
            GetArrayDim = i_   n7U中国设计秀
        End If  n7U中国设计秀
    End Function n7U中国设计秀
    Private Function GetNumFormatLocal(DataType)n7U中国设计秀
        Select Case DataTypen7U中国设计秀
            Case "Currency":n7U中国设计秀
                GetNumFormatLocal = "¥#,##0.00_);(¥#,##0.00)"n7U中国设计秀
            Case "Time":n7U中国设计秀
                GetNumFormatLocal = "[$-F800]dddd, mmmm dd, yyyy"n7U中国设计秀
            Case "Char":n7U中国设计秀
                GetNumFormatLocal = "@"n7U中国设计秀
            Case "Common":n7U中国设计秀
                GetNumFormatLocal = "G/通用格式"n7U中国设计秀
            Case "Number":n7U中国设计秀
                GetNumFormatLocal = "#,##0.00_"n7U中国设计秀
            Case else :n7U中国设计秀
                GetNumFormatLocal = "@"n7U中国设计秀
        End Selectn7U中国设计秀
    End Functionn7U中国设计秀
    Public Sub AddDBData(ByVal RsFlied, ByVal FliedTitle, ByVal tempSheetName_, ByVal tempSheetTitle_, DBTitle)n7U中国设计秀
        if RsFlied.Eof then Exit Subn7U中国设计秀
        Dim colNum_ : colNum_ = RsFlied.fields.countn7U中国设计秀
        Dim Rownum_ : Rownum_ = RsFlied.RecordCountn7U中国设计秀
        Dim ArrFliedTitlen7U中国设计秀
        n7U中国设计秀
        if DBTitle = true thenn7U中国设计秀
            FliedTitle = ""n7U中国设计秀
            Dim ig_n7U中国设计秀
            For ig_=0 to colNum_ - 1n7U中国设计秀
                FliedTitle = FliedTitle & RsFlied.fields.item(ig_).namen7U中国设计秀
                if ig_ <> colNum_ - 1 then FliedTitle = FliedTitle &","n7U中国设计秀
            Nextn7U中国设计秀
        end ifn7U中国设计秀
        n7U中国设计秀
        if FliedTitle<>"" thenn7U中国设计秀
            Rownum_ = Rownum_ + 1n7U中国设计秀
            ArrFliedTitle = Split(FliedTitle, ",")n7U中国设计秀
            if Ubound(ArrFliedTitle) <> colNum_ - 1  thenn7U中国设计秀
                InErr("获取数据库表有误,列数不符")n7U中国设计秀
            end ifn7U中国设计秀
        end if    n7U中国设计秀
        Dim tempData : ReDim tempData(Rownum_ - 1, colNum_ - 1)n7U中国设计秀
        n7U中国设计秀
        Dim ix_, iy_n7U中国设计秀
        Dim izn7U中国设计秀
        if FliedTitle<>"" then iz = Rownum_ - 2  else iz = Rownum_ - 1n7U中国设计秀
        n7U中国设计秀
        For ix_ = 0 To izn7U中国设计秀
            For iy_ = 0 To colNum_ - 1n7U中国设计秀
                if FliedTitle<>"" thenn7U中国设计秀
                    if ix_=0 thenn7U中国设计秀
                        tempData(ix_, iy_) = ArrFliedTitle(iy_)n7U中国设计秀
                        tempData(ix_ + 1, iy_) = RsFlied(iy_)n7U中国设计秀
                    elsen7U中国设计秀
                        tempData(ix_ + 1, iy_) = RsFlied(iy_)n7U中国设计秀
                    end ifn7U中国设计秀
                elsen7U中国设计秀
                    tempData(ix_, iy_) = RsFlied(iy_)n7U中国设计秀
                end ifn7U中国设计秀
            Nextn7U中国设计秀
            RsFlied.MoveNextn7U中国设计秀
        Nextn7U中国设计秀
        n7U中国设计秀
        Dim tempFirstLine n7U中国设计秀
        if FliedTitle<>"" then tempFirstLine = true else tempFirstLine = falsen7U中国设计秀
        Call AddData(tempData, tempFirstLine, tempSheetName_, tempSheetTitle_)n7U中国设计秀
    End Subn7U中国设计秀
    Public Sub AddData(ByVal tempDate_, ByVal tempFirstLine_, ByVal tempSheetName_, ByVal tempSheetTitle_)n7U中国设计秀
        if not isArray(excelData) thenn7U中国设计秀
            excelData = tempDate_n7U中国设计秀
            TitleFirstLine = tempFirstLine_n7U中国设计秀
            SheetName_ = tempSheetName_n7U中国设计秀
            SheetTitle_ = tempSheetTitle_n7U中国设计秀
        elsen7U中国设计秀
            if GetArrayDim(excelData) = 1 thenn7U中国设计秀
                Dim tempArrLen : tempArrLen = Ubound(excelData)+1n7U中国设计秀
                ReDim Preserve excelData(tempArrLen)n7U中国设计秀
                excelData(tempArrLen) = tempDate_n7U中国设计秀
                ReDim Preserve TitleFirstLine(tempArrLen)n7U中国设计秀
                TitleFirstLine(tempArrLen) = tempFirstLine_n7U中国设计秀
                ReDim Preserve SheetName_(tempArrLen)n7U中国设计秀
                SheetName_(tempArrLen) = tempSheetName_n7U中国设计秀
                ReDim Preserve SheetTitle_(tempArrLen)n7U中国设计秀
                SheetTitle_(tempArrLen) = tempSheetTitle_n7U中国设计秀
            elsen7U中国设计秀
                Dim tempOldData : tempOldData = excelDatan7U中国设计秀
                excelData = Array(tempOldData, tempDate_)n7U中国设计秀
                TitleFirstLine = Array(TitleFirstLine, tempFirstLine_)n7U中国设计秀
                SheetName_ = Array(SheetName_, tempSheetName_)n7U中国设计秀
                SheetTitle_ = Array(SheetTitle_, tempSheetTitle_)n7U中国设计秀
            end ifn7U中国设计秀
        end ifn7U中国设计秀
    End Subn7U中国设计秀
    Rem 模板增加数据方法n7U中国设计秀
    Public Sub AddtData(ByVal tempDate_, ByVal tempSheetName_)n7U中国设计秀
        CreateType_ = 2n7U中国设计秀
        if not isArray(excelData) thenn7U中国设计秀
            excelData = Array(tempDate_)n7U中国设计秀
            SheetName_ = Array(tempSheetName_)n7U中国设计秀
        elsen7U中国设计秀
            Dim tempArrLen : tempArrLen = Ubound(excelData)+1n7U中国设计秀
            ReDim Preserve excelData(tempArrLen)n7U中国设计秀
            excelData(tempArrLen) = tempDate_n7U中国设计秀
            ReDim Preserve SheetName_(tempArrLen)n7U中国设计秀
            SheetName_(tempArrLen) = tempSheetName_n7U中国设计秀
        End ifn7U中国设计秀
    End Subn7U中国设计秀
    Private Sub SetSheets(ByVal Data_, DataId_)n7U中国设计秀
        Dim Spreadsheetn7U中国设计秀
        set Spreadsheet = excelBook.Sheets(SheetName_(DataId_))n7U中国设计秀
        Spreadsheet.Activaten7U中国设计秀
        Dim ix_n7U中国设计秀
        For ix_ =0 To Ubound(Data_)n7U中国设计秀
            if not isArray(Data_(ix_)) then InErr("表数据载入有误,数据格式错误")n7U中国设计秀
            if Ubound(Data_(ix_)) <> 1 then InErr("表数据载入有误,数据格式错误")n7U中国设计秀
            Spreadsheet.Range(Data_(ix_)(0)).value = Data_(ix_)(1)n7U中国设计秀
        Nextn7U中国设计秀
        set Spreadsheet = Nothingn7U中国设计秀
    End Subn7U中国设计秀
    Public Function GetTime(msec_)n7U中国设计秀
        Dim ReTime_ : ReTime_=""n7U中国设计秀
        if msec_ < 1000 thenn7U中国设计秀
            ReTime_ = msec_ &"MS"n7U中国设计秀
        elsen7U中国设计秀
            Dim second_n7U中国设计秀
            second_ = (msec_ 1000)n7U中国设计秀
            if (msec_ mod 1000)<>0 thenn7U中国设计秀
                msec_ = (msec_ mod 1000) &"毫秒"n7U中国设计秀
            elsen7U中国设计秀
                msec_ = ""n7U中国设计秀
            end ifn7U中国设计秀
            Dim n_, aryTime(2), aryTimeunit(2)n7U中国设计秀
            aryTimeunit(0) = "秒"n7U中国设计秀
            aryTimeunit(1) = "分"n7U中国设计秀
            aryTimeunit(2) = "小时"n7U中国设计秀
            n_ = 0n7U中国设计秀
            Dim tempSecond_ : tempSecond_ = second_n7U中国设计秀
            While(tempSecond_ / 60 >= 1)n7U中国设计秀
                tempSecond_ = Fix(tempSecond_ / 60 * 100) / 100n7U中国设计秀
                n_ = n_ + 1n7U中国设计秀
            WEndn7U中国设计秀
            Dim m_n7U中国设计秀
            For m_ = n_ To 0 Step -1n7U中国设计秀
                aryTime(m_) = second_ (60 ^ m_)n7U中国设计秀
                second_ = second_ mod (60 ^ m_)n7U中国设计秀
                ReTime_ = ReTime_ & aryTime(m_) & aryTimeunit(m_)n7U中国设计秀
            Nextn7U中国设计秀
            if msec_<>"" then ReTime_ = ReTime_ & msec_n7U中国设计秀
        end ifn7U中国设计秀
        GetTime = ReTime_ n7U中国设计秀
    end Functionn7U中国设计秀
    Rem 取得列名n7U中国设计秀
    Private Function getColName(ByVal ColNum)n7U中国设计秀
        Dim Arrlitter : Arrlitter=split("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z", " ")n7U中国设计秀
        Dim ReValue_n7U中国设计秀
        if ColNum <= Ubound(Arrlitter) + 1 then n7U中国设计秀
            ReValue_ = Arrlitter(ColNum - 1)n7U中国设计秀
        elsen7U中国设计秀
            ReValue_ = Arrlitter(((ColNum-1) 26)) & Arrlitter(((ColNum-1) mod 26))n7U中国设计秀
        end ifn7U中国设计秀
        getColName = ReValue_n7U中国设计秀
    End Functionn7U中国设计秀
    Rem 设置错误n7U中国设计秀
    Private Sub InErr(ErrInfo)n7U中国设计秀
        Err.Raise vbObjectError + 1, SystemStr &"(Version "& VersionStr &")", ErrInfon7U中国设计秀
    End Subn7U中国设计秀
End Classn7U中国设计秀
Dim b(4,6)n7U中国设计秀
Dim c(50,20)n7U中国设计秀
Dim i, jn7U中国设计秀
For i=0 to 4n7U中国设计秀
    For j=0 to 6n7U中国设计秀
        b(i,j) =i&"-"&jn7U中国设计秀
    Nextn7U中国设计秀
Nextn7U中国设计秀
For i=0 to 50n7U中国设计秀
    For j=0 to 20n7U中国设计秀
        c(i,j) = i&"-"&j &"我的"n7U中国设计秀
    Nextn7U中国设计秀
Nextn7U中国设计秀
Dim e(20)n7U中国设计秀
For i=0 to 20n7U中国设计秀
    e(i)= array("A"&(i+1), i+1)n7U中国设计秀
Nextn7U中国设计秀
'使用示例  需要xx.xls模板支持n7U中国设计秀
'Set a=new Createexceln7U中国设计秀
'a.ReadPath = "xx.xls"n7U中国设计秀
'a.SavePath="xx-1.xls"n7U中国设计秀
'a.AddtData e, "Sheet1"n7U中国设计秀
'a.Create()n7U中国设计秀
'response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")n7U中国设计秀
'Set a=nothingn7U中国设计秀
'使用示例一n7U中国设计秀
Set a=new Createexceln7U中国设计秀
a.SavePath="x.xls"n7U中国设计秀
a.AddData b, true , "测试c", "测试c"n7U中国设计秀
a.TitleFirstLine = false '首行是否为标题行n7U中国设计秀
a.Create()n7U中国设计秀
response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")n7U中国设计秀
Set a=nothingn7U中国设计秀
'使用示例二n7U中国设计秀
Set a=new Createexceln7U中国设计秀
a.SavePath="y.xls"n7U中国设计秀
a.SheetName="工作簿名称"       '多个工作表 a.SheetName=array("工作簿名称一","工作簿名称二")n7U中国设计秀
a.SheetTitle="表名称"         '可以为空  多个工作表 a.SheetName=array("表名称一","表名称二")n7U中国设计秀
a.Data =b '二维数组             '多个工作表 array(b,c) b与c为二维数组n7U中国设计秀
a.Create()n7U中国设计秀
response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")n7U中国设计秀
Set a=nothingn7U中国设计秀
'使用示例三 生成两个表n7U中国设计秀
Set a=new Createexceln7U中国设计秀
a.SavePath="z.xls"n7U中国设计秀
a.SheetName=array("工作簿名称一","工作簿名称二")n7U中国设计秀
a.SheetTitle=array("表名称一","表名称二")n7U中国设计秀
a.Data =array(b, c) 'b与c为二维数组n7U中国设计秀
a.TitleFirstLine = array(false, true) '首行是否为标题行n7U中国设计秀
a.Create()n7U中国设计秀
response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")n7U中国设计秀
Set a=nothingn7U中国设计秀
'使用示例四    需要数据库支持n7U中国设计秀
'Dim rsn7U中国设计秀
'Set rs=server.CreateObject("Adodb.RecordSet")n7U中国设计秀
'rs.open "Select id, classid, className from [class] ",conn, 1, 1n7U中国设计秀
'Set a=new Createexceln7U中国设计秀
'a.SavePath="a"n7U中国设计秀
'a.AddDBData rs, "序号,类别序号,类别名称", "工作簿名称", "类别表", falsen7U中国设计秀
'a.Create()n7U中国设计秀
'response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")n7U中国设计秀
'Set a=nothingn7U中国设计秀
'rs.closen7U中国设计秀
'Set rs=nothingn7U中国设计秀
%>n7U中国设计秀
 n7U中国设计秀

本文引用地址:/bc/article_46237.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明