请选择 进入手机版 | 继续访问电脑版
收藏本站腾讯微博新浪微博
点点网模板设计大赛 phpchina

经典论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

蓝色理想 最新研发动态 用悬赏 三天解决问题 解决访问速度慢 论坛支持农历生日 - 给官方提建议

论坛活动及任务 归纳网站最新活动 地图任务 邮件更新任务:保护帐号安全

积分换实物,来参加蓝色理想积分兑换吧! 联系招聘客服 蓝色理想帮你找工作! 万元奖励等你拿——点点网模板设计大赛

查看: 10190|回复: 10

[asp] [原创]asp操作Excel类 [复制链接]

surnfu 楼主

大和尚

银牌会员

帖子
219
体力
1133
威望
2
发表于 2009-6-26 17:26:37 |显示全部楼层
  1. <%
  2. '***************************************************************************************
  3. '使用说明
  4. 'Dim a
  5. 'Set a=new CreateExcel
  6. 'a.SavePath="x" '保存路径
  7. 'a.SheetName="工作簿名称"           '多个工作表 a.SheetName=array("工作簿名称一","工作簿名称二")
  8. 'a.SheetTitle="表名称"                 '可以为空  多个工作表 a.SheetName=array("表名称一","表名称二")
  9. 'a.Data =d '二维数组                         '多个工作表 array(b,c) b与c为二维数组
  10. 'Dim rs
  11. 'Set rs=server.CreateObject("Adodb.RecordSet")
  12. 'rs.open "Select id, classid, className from [class] ",conn, 1, 1
  13. 'a.AddDBData rs, "字段名一,字段名二", "工作簿名称", "表名称",         true    'true自动获取表字段名
  14. 'a.AddData c, true , "工作簿名称", "表名称"    'c二维数组                  true  第一行是否为标题行
  15. 'a.AddtData e, "Sheet1"   '按模板生成  c=array(array("AA1", "内容"), array("AA2", "内容2"))
  16. 'a.Create()
  17. 'a.UsedTime                生成时间,毫秒数
  18. 'a.SavePath                保存路径
  19. 'Set a=nothing
  20. '设置COM组件的操作权限。在命令行键入“DCOMCNFG”,则进入COM组件配置界面,选择MicrosoftExcel后点击属性按钮,将三个单选项一律选择自定义,编辑中将Everyone加入所有权限
  21. '****************************************************************************************
  22. Class CreateExcel
  23.         Private CreateType_
  24.         Private savePath_
  25.         Private readPath_
  26.         Private AuthorStr                          Rem 设置作者
  27.         Private VersionStr                  Rem 设置版本
  28.         Private SystemStr                          Rem 设置系统名称
  29.         Private SheetName_                         Rem 设置表名
  30.         Private SheetTitle_                 Rem 设置标题
  31.         Private ExcelData                         Rem 设置表数据
  32.         Private ExcelApp                         Rem Excel.Application
  33.         Private ExcelBook
  34.         Private ExcelSheets
  35.         Private UsedTime_                        Rem 使用的时间
  36.         Public TitleFirstLine                Rem 首行是否标题

  37.         Private Sub Class_Initialize()
  38.                 Server.ScriptTimeOut = 99999
  39.                 UsedTime_ = Timer
  40.                 SystemStr                        =        "Lc00_CreateExcelServer"
  41.                 AuthorStr                        =        "Surnfu  surnfu@126.com  31333716"
  42.                 VersionStr                        =        "1.0"
  43.                 if not IsObjInstalled("Excel.Application") then
  44.                         InErr("服务器未安装Excel.Application控件")
  45.                 end if
  46.                 set ExcelApp = createObject("Excel.Application")
  47.                 ExcelApp.DisplayAlerts = false
  48.                 ExcelApp.Application.Visible = false
  49.                 CreateType_ = 1
  50.                 readPath_ = null
  51.         End Sub

  52.         Private Sub Class_Terminate()
  53.                 ExcelApp.Quit
  54.                 If Isobject(ExcelSheets)         Then Set ExcelSheets        =        Nothing
  55.                 If Isobject(ExcelBook)                 Then Set ExcelBook                =        Nothing
  56.                 If Isobject(ExcelApp)                 Then Set ExcelApp                =        Nothing
  57.         End Sub

  58.         Public Property Let ReadPath(ByVal Val)
  59.                 If Instr(Val, ":\")<>0 Then
  60.                         readPath_ = Trim(Val)
  61.                 else
  62.                         readPath_=Server.MapPath(Trim(Val))
  63.                 end if
  64.         End Property

  65.         Public Property Let SavePath(ByVal Val)
  66.                 If Instr(Val, ":\")<>0 Then
  67.                         savePath_ = Trim(Val)
  68.                 else
  69.                         savePath_=Server.MapPath(Trim(Val))
  70.                 end if
  71.         End Property
  72.        
  73.        
  74.         Public Property Let CreateType(ByVal Val)
  75.                 if Val <> 1 and Val <> 2 then
  76.                         CreateType_ = 1
  77.                 else
  78.                         CreateType_ = Val
  79.                 end if       
  80.         End Property
  81.        
  82.         Public Property Let Data(ByVal Val)
  83.                 if not isArray(Val) then
  84.                         InErr("表数据设置有误")
  85.                 end if
  86.                   ExcelData = Val
  87.         End Property

  88.         Public Property Get SavePath()
  89.         SavePath = savePath_
  90.         End Property

  91.         Public Property Get UsedTime()
  92.                   UsedTime = UsedTime_
  93.         End Property

  94.         Public Property Let SheetName(ByVal Val)
  95.                 if not isArray(Val) then
  96.                         if Val = "" then
  97.                                 InErr("表名设置有误")
  98.                         end if
  99.                         TitleFirstLine = true
  100.                 else
  101.                         ReDim TitleFirstLine(Ubound(Val))
  102.                         Dim ik_
  103.                         For ik_ = 0 to Ubound(Val)
  104.                                 TitleFirstLine(ik_) = true
  105.                         Next
  106.                 end if
  107.                   SheetName_ = Val
  108.         End Property
  109.        
  110.         Public Property Let SheetTitle(ByVal Val)
  111.                 if not isArray(Val) then
  112.                         if Val = "" then
  113.                                 InErr("表标题设置有误")
  114.                         end if
  115.                 end if
  116.                   SheetTitle_ = Val
  117.         End Property
  118.        
  119.         Rem 检查数据
  120.         Private Sub CheckData()
  121.                 if savePath_ = "" then InErr("保存路径不能为空")
  122.                 if not isArray(SheetName_) then
  123.                         if SheetName_ = "" then InErr("表名不能为空")
  124.                 end if
  125.                
  126.                 if CreateType_ = 2 then
  127.                         if not isArray(ExcelData) then
  128.                                 InErr("数据载入错误,或者未载入")
  129.                         end if
  130.                         Exit Sub
  131.                 end if
  132.                
  133.                 if isArray(SheetName_) then
  134.                         if not isArray(SheetTitle_) then
  135.                                 if SheetTitle_ <> "" then InErr("表标题设置有误,与表名不对应")
  136.                         end if
  137.                 end if

  138.                 if not IsArray(ExcelData) then
  139.                         InErr("表数据载入有误")
  140.                 end if

  141.                 if isArray(SheetName_) then
  142.                         if GetArrayDim(ExcelData) <> 1 then InErr("表数据载入有误,数据格式错误,维度应该为一")
  143.                 else
  144.                         if GetArrayDim(ExcelData) <> 2 then InErr("表数据载入有误,数据格式错误,维度应该为二")
  145.                 end if

  146.         End Sub



  147.         Rem 生成Excel
  148.         Public Function Create()
  149.                 Call CheckData()
  150.                 if not isnull(readPath_) then
  151.                         ExcelApp.WorkBooks.Open(readPath_)
  152.                 else
  153.                         ExcelApp.WorkBooks.add
  154.                 end if
  155.                
  156.                 set ExcelBook = ExcelApp.ActiveWorkBook
  157.                 set ExcelSheets = ExcelBook.Worksheets
  158.                
  159.                 if CreateType_ = 2 then
  160.                         Dim ih_
  161.                         For ih_ = 0 to Ubound(ExcelData)
  162.                                 Call SetSheets(ExcelData(ih_), ih_)
  163.                         Next
  164.                         ExcelBook.SaveAs savePath_
  165.                         UsedTime_ = FormatNumber((Timer - UsedTime_)*1000, 3)
  166.                         Exit Function
  167.                 end if
  168.                
  169.                 if IsArray(SheetName_) then
  170.                         Dim ik_
  171.                         For ik_ = 0 to Ubound(ExcelData)
  172.                                 Call CreateSheets(ExcelData(ik_), ik_)
  173.                         Next
  174.                 else
  175.                         Call CreateSheets(ExcelData, -1)
  176.                 end if
  177.                
  178.                 ExcelBook.SaveAs savePath_
  179.                 UsedTime_ = FormatNumber((Timer - UsedTime_)*1000, 3)
  180.         End Function

  181.         Private Sub CreateSheets(ByVal Data_, DataId_)
  182.                 Dim Spreadsheet
  183.                 Dim tempSheetTitle
  184.                 Dim tempTitleFirstLine
  185.                 if DataId_<>-1 then
  186.                         if DataId_ > ExcelSheets.Count - 1 then
  187.                                 ExcelSheets.Add()
  188.                                 set Spreadsheet = ExcelBook.Sheets(1)
  189.                         else
  190.                                 set Spreadsheet = ExcelBook.Sheets(DataId_ + 1)
  191.                         end if
  192.                         if isArray(SheetTitle_) then
  193.                                 tempSheetTitle = SheetTitle_(DataId_)
  194.                         else
  195.                                 tempSheetTitle = ""
  196.                         end if
  197.                         tempTitleFirstLine = TitleFirstLine(DataId_)
  198.                         Spreadsheet.Name = SheetName_(DataId_)
  199.                 else
  200.                         set Spreadsheet = ExcelBook.Sheets(1)
  201.                         Spreadsheet.Name = SheetName_
  202.                         tempSheetTitle = SheetTitle_
  203.                         tempTitleFirstLine = TitleFirstLine
  204.                 end if
  205.                 Dim Line_ : Line_ = 1
  206.                 Dim RowNum_ : RowNum_ = Ubound(Data_, 1) + 1
  207.                 Dim LastCols_
  208.                 if tempSheetTitle <> "" then
  209.                         'Spreadsheet.Columns(1).ShrinkToFit=true '设定是否自动适应表格单元大小(单元格宽不变)
  210.                         LastCols_ = getColName(Ubound(Data_, 2) + 1)
  211.                         with Spreadsheet.Cells(1, 1)
  212.                                 .value = tempSheetTitle
  213.                                 '设置Excel表里的字体
  214.                                 .Font.Bold = True '单元格字体加粗
  215.                                 .Font.Italic = False '单元格字体倾斜
  216.                                 .Font.Size = 20 '设置单元格字号
  217.                                 .font.name="宋体" '设置单元格字体
  218.                                 '.font.ColorIndex=2 '设置单元格文字的颜色,颜色可以查询,2为白色
  219.                         End with
  220.                         with Spreadsheet.Range("A1:"& LastCols_ &"1")
  221.                                 .merge '合并单元格(单元区域)
  222.                                 '.Interior.ColorIndex = 1 '设计单元络背景色
  223.                                 .HorizontalAlignment = 3 '居中
  224.                         End with
  225.                         Line_ = 2
  226.                         RowNum_ = RowNum_ + 1
  227.                 end if
  228.                 Dim iRow_, iCol_
  229.                 Dim dRow_, dCol_
  230.                 Dim tempLastRange : tempLastRange = getColName(Ubound(Data_, 2)+1) & (RowNum_)
  231.                
  232.                 Dim BeginRow : BeginRow = 1
  233.                 if tempSheetTitle <> "" then BeginRow = BeginRow + 1
  234.                 if tempTitleFirstLine = true then BeginRow = BeginRow + 1
  235.                
  236.                 if BeginRow=1 then
  237.                         with Spreadsheet.Range("A1:"& tempLastRange)
  238.                                 .Borders.LineStyle = 1
  239.                                 .BorderAround -4119, -4138 '设置外框
  240.                                 .NumberFormatLocal = "@"   '文本格式
  241.                                 .Font.Bold = False
  242.                                 .Font.Italic = False
  243.                                 .Font.Size = 10
  244.                                 .ShrinkToFit=true
  245.                         end with
  246.                 else
  247.                         with Spreadsheet.Range("A1:"& tempLastRange)
  248.                                 .Borders.LineStyle = 1
  249.                                 .BorderAround -4119, -4138
  250.                                 .ShrinkToFit=true
  251.                         end with
  252.                        
  253.                         with Spreadsheet.Range("A"& BeginRow &":"& tempLastRange)
  254.                                 .NumberFormatLocal = "@"
  255.                                 .Font.Bold = False
  256.                                 .Font.Italic = False
  257.                                 .Font.Size = 10
  258.                         end with
  259.                 end if
  260.                
  261.                 if tempTitleFirstLine = true then
  262.                         BeginRow = 1
  263.                         if tempSheetTitle <> "" then BeginRow = BeginRow + 1
  264.                
  265.                         with Spreadsheet.Range("A"& BeginRow &":"& getColName(Ubound(Data_, 2)+1) & (BeginRow))
  266.                                 .NumberFormatLocal = "@"
  267.                                 .Font.Bold = True
  268.                                 .Font.Italic = False
  269.                                 .Font.Size = 12
  270.                                 .Interior.ColorIndex = 37
  271.                                 .HorizontalAlignment = 3 '居中
  272.                                 .font.ColorIndex=2
  273.                         end with
  274.                 end if
  275.                
  276.                 For iRow_ = Line_ To RowNum_
  277.                         For iCol_ = 1 To (Ubound(Data_, 2) + 1)
  278.                                 dCol_ = iCol_ - 1
  279.                                 if tempSheetTitle <> "" then dRow_ = iRow_ - 2 else dRow_ = iRow_ - 1
  280.                                 If not IsNull(Data_(dRow_, dCol_)) then
  281.                                         with Spreadsheet.Cells(iRow_, iCol_)
  282.                                                 .Value = Data_(dRow_, dCol_)
  283.                                         End with
  284.                                 End If
  285.                         Next
  286.                 Next
  287.                 set Spreadsheet = Nothing
  288.         End Sub

  289.         Rem 测试组件是否已经安装
  290.         Private Function IsObjInstalled(strClassString)
  291.                 On Error Resume Next
  292.                 IsObjInstalled = False
  293.                 Err = 0
  294.                 Dim xTestObj
  295.                 Set xTestObj = Server.CreateObject(strClassString)
  296.                 If 0 = Err Then IsObjInstalled = True
  297.                 Set xTestObj = Nothing
  298.                 Err = 0
  299.         End Function

  300.         Rem 取得数组维数
  301.         Private Function GetArrayDim(ByVal arr)   
  302.                 GetArrayDim = Null   
  303.                 Dim i_, temp   
  304.                 If IsArray(arr) Then  
  305.                         For i_ = 1 To 60   
  306.                                 On Error Resume Next  
  307.                                 temp = UBound(arr, i_)   
  308.                                 If Err.Number <> 0 Then  
  309.                                         GetArrayDim = i_ - 1
  310.                                         Err.Clear
  311.                                         Exit Function  
  312.                                 End If  
  313.                         Next  
  314.                         GetArrayDim = i_   
  315.                 End If  
  316.         End Function

  317.         Private Function GetNumFormatLocal(DataType)
  318.                 Select Case DataType
  319.                         Case "Currency":
  320.                                 GetNumFormatLocal = "¥#,##0.00_);(¥#,##0.00)"
  321.                         Case "Time":
  322.                                 GetNumFormatLocal = "[$-F800]dddd, mmmm dd, yyyy"
  323.                         Case "Char":
  324.                                 GetNumFormatLocal = "@"
  325.                         Case "Common":
  326.                                 GetNumFormatLocal = "G/通用格式"
  327.                         Case "Number":
  328.                                 GetNumFormatLocal = "#,##0.00_"
  329.                         Case else :
  330.                                 GetNumFormatLocal = "@"
  331.                 End Select
  332.         End Function

  333.         Public Sub AddDBData(ByVal RsFlied, ByVal FliedTitle, ByVal tempSheetName_, ByVal tempSheetTitle_, DBTitle)
  334.                 if RsFlied.Eof then Exit Sub
  335.                 Dim colNum_ : colNum_ = RsFlied.fields.count
  336.                 Dim Rownum_ : Rownum_ = RsFlied.RecordCount
  337.                 Dim ArrFliedTitle
  338.                
  339.                 if DBTitle = true then
  340.                         FliedTitle = ""
  341.                         Dim ig_
  342.                         For ig_=0 to colNum_ - 1
  343.                                 FliedTitle = FliedTitle & RsFlied.fields.item(ig_).name
  344.                                 if ig_ <> colNum_ - 1 then FliedTitle = FliedTitle &","
  345.                         Next
  346.                 end if
  347.                
  348.                 if FliedTitle<>"" then
  349.                         Rownum_ = Rownum_ + 1
  350.                         ArrFliedTitle = Split(FliedTitle, ",")
  351.                         if Ubound(ArrFliedTitle) <> colNum_ - 1  then
  352.                                 InErr("获取数据库表有误,列数不符")
  353.                         end if
  354.                 end if       
  355.                 Dim tempData : ReDim tempData(Rownum_ - 1, colNum_ - 1)
  356.                
  357.                 Dim ix_, iy_
  358.                 Dim iz
  359.                 if FliedTitle<>"" then iz = Rownum_ - 2  else iz = Rownum_ - 1
  360.                
  361.                 For ix_ = 0 To iz
  362.                         For iy_ = 0 To colNum_ - 1
  363.                                 if FliedTitle<>"" then
  364.                                         if ix_=0 then
  365.                                                 tempData(ix_, iy_) = ArrFliedTitle(iy_)
  366.                                                 tempData(ix_ + 1, iy_) = RsFlied(iy_)
  367.                                         else
  368.                                                 tempData(ix_ + 1, iy_) = RsFlied(iy_)
  369.                                         end if
  370.                                 else
  371.                                         tempData(ix_, iy_) = RsFlied(iy_)
  372.                                 end if
  373.                         Next
  374.                         RsFlied.MoveNext
  375.                 Next
  376.                
  377.                 Dim tempFirstLine
  378.                 if FliedTitle<>"" then tempFirstLine = true else tempFirstLine = false
  379.                 Call AddData(tempData, tempFirstLine, tempSheetName_, tempSheetTitle_)
  380.         End Sub



  381.         Public Sub AddData(ByVal tempDate_, ByVal tempFirstLine_, ByVal tempSheetName_, ByVal tempSheetTitle_)
  382.                 if not isArray(ExcelData) then
  383.                         ExcelData = tempDate_
  384.                         TitleFirstLine = tempFirstLine_
  385.                         SheetName_ = tempSheetName_
  386.                         SheetTitle_ = tempSheetTitle_
  387.                 else
  388.                         if GetArrayDim(ExcelData) = 1 then
  389.                                 Dim tempArrLen : tempArrLen = Ubound(ExcelData)+1
  390.                                 ReDim Preserve ExcelData(tempArrLen)
  391.                                 ExcelData(tempArrLen) = tempDate_
  392.                                 ReDim Preserve TitleFirstLine(tempArrLen)
  393.                                 TitleFirstLine(tempArrLen) = tempFirstLine_
  394.                                 ReDim Preserve SheetName_(tempArrLen)
  395.                                 SheetName_(tempArrLen) = tempSheetName_
  396.                                 ReDim Preserve SheetTitle_(tempArrLen)
  397.                                 SheetTitle_(tempArrLen) = tempSheetTitle_
  398.                         else
  399.                                 Dim tempOldData : tempOldData = ExcelData
  400.                                 ExcelData = Array(tempOldData, tempDate_)
  401.                                 TitleFirstLine = Array(TitleFirstLine, tempFirstLine_)
  402.                                 SheetName_ = Array(SheetName_, tempSheetName_)
  403.                                 SheetTitle_ = Array(SheetTitle_, tempSheetTitle_)
  404.                         end if
  405.                 end if
  406.         End Sub


  407.         Rem 模板增加数据方法
  408.         Public Sub AddtData(ByVal tempDate_, ByVal tempSheetName_)
  409.                 CreateType_ = 2
  410.                 if not isArray(ExcelData) then
  411.                         ExcelData = Array(tempDate_)
  412.                         SheetName_ = Array(tempSheetName_)
  413.                 else
  414.                         Dim tempArrLen : tempArrLen = Ubound(ExcelData)+1
  415.                         ReDim Preserve ExcelData(tempArrLen)
  416.                         ExcelData(tempArrLen) = tempDate_
  417.                         ReDim Preserve SheetName_(tempArrLen)
  418.                         SheetName_(tempArrLen) = tempSheetName_
  419.                 End if
  420.         End Sub

  421.         Private Sub SetSheets(ByVal Data_, DataId_)
  422.                 Dim Spreadsheet
  423.                 set Spreadsheet = ExcelBook.Sheets(SheetName_(DataId_))
  424.                 Spreadsheet.Activate

  425.                 Dim ix_
  426.                 For ix_ =0 To Ubound(Data_)
  427.                         if not isArray(Data_(ix_)) then InErr("表数据载入有误,数据格式错误")
  428.                         if Ubound(Data_(ix_)) <> 1 then InErr("表数据载入有误,数据格式错误")
  429.                         Spreadsheet.Range(Data_(ix_)(0)).value = Data_(ix_)(1)
  430.                 Next
  431.                 set Spreadsheet = Nothing
  432.         End Sub


  433.         Public Function GetTime(msec_)
  434.                 Dim ReTime_ : ReTime_=""
  435.                 if msec_ < 1000 then
  436.                         ReTime_ = msec_ &"MS"
  437.                 else
  438.                         Dim second_
  439.                         second_ = (msec_ \ 1000)
  440.                         if (msec_ mod 1000)<>0 then
  441.                                 msec_ = (msec_ mod 1000) &"毫秒"
  442.                         else
  443.                                 msec_ = ""
  444.                         end if
  445.                         Dim n_, aryTime(2), aryTimeunit(2)
  446.                         aryTimeunit(0) = "秒"
  447.                         aryTimeunit(1) = "分"
  448.                         aryTimeunit(2) = "小时"
  449.                         n_ = 0
  450.                         Dim tempSecond_ : tempSecond_ = second_
  451.                         While(tempSecond_ / 60 >= 1)
  452.                                 tempSecond_ = Fix(tempSecond_ / 60 * 100) / 100
  453.                                 n_ = n_ + 1
  454.                         WEnd
  455.                         Dim m_
  456.                         For m_ = n_ To 0 Step -1
  457.                                 aryTime(m_) = second_ \ (60 ^ m_)
  458.                                 second_ = second_ mod (60 ^ m_)
  459.                                 ReTime_ = ReTime_ & aryTime(m_) & aryTimeunit(m_)
  460.                         Next
  461.                         if msec_<>"" then ReTime_ = ReTime_ & msec_
  462.                 end if
  463.                 GetTime = ReTime_
  464.         end Function

  465.         Rem 取得列名
  466.         Private Function getColName(ByVal ColNum)
  467.                 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", " ")
  468.                 Dim ReValue_
  469.                 if ColNum <= Ubound(Arrlitter) + 1 then
  470.                         ReValue_ = Arrlitter(ColNum - 1)
  471.                 else
  472.                         ReValue_ = Arrlitter(((ColNum-1) \ 26)) & Arrlitter(((ColNum-1) mod 26))
  473.                 end if
  474.                 getColName = ReValue_
  475.         End Function

  476.         Rem 设置错误
  477.         Private Sub InErr(ErrInfo)
  478.                 Err.Raise vbObjectError + 1, SystemStr &"(Version "& VersionStr &")", ErrInfo
  479.         End Sub

  480. End Class



  481. Dim b(4,6)
  482. Dim c(50,20)
  483. Dim i, j
  484. For i=0 to 4
  485.         For j=0 to 6
  486.                 b(i,j) =i&"-"&j
  487.         Next
  488. Next

  489. For i=0 to 50
  490.         For j=0 to 20
  491.                 c(i,j) = i&"-"&j &"我的"
  492.         Next
  493. Next

  494. Dim e(20)
  495. For i=0 to 20
  496.         e(i)= array("A"&(i+1), i+1)
  497. Next

  498. '使用示例  需要xx.xls模板支持
  499. 'Set a=new CreateExcel
  500. 'a.ReadPath = "xx.xls"
  501. 'a.SavePath="xx-1.xls"
  502. 'a.AddtData e, "Sheet1"
  503. 'a.Create()
  504. 'response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")
  505. 'Set a=nothing




  506. '使用示例一
  507. Set a=new CreateExcel
  508. a.SavePath="x.xls"
  509. a.AddData b, true , "测试c", "测试c"
  510. a.TitleFirstLine = false '首行是否为标题行
  511. a.Create()
  512. response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")
  513. Set a=nothing


  514. '使用示例二
  515. Set a=new CreateExcel
  516. a.SavePath="y.xls"
  517. a.SheetName="工作簿名称"           '多个工作表 a.SheetName=array("工作簿名称一","工作簿名称二")
  518. a.SheetTitle="表名称"                 '可以为空  多个工作表 a.SheetName=array("表名称一","表名称二")
  519. a.Data =b '二维数组                         '多个工作表 array(b,c) b与c为二维数组
  520. a.Create()
  521. response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")
  522. Set a=nothing


  523. '使用示例三 生成两个表
  524. Set a=new CreateExcel
  525. a.SavePath="z.xls"
  526. a.SheetName=array("工作簿名称一","工作簿名称二")
  527. a.SheetTitle=array("表名称一","表名称二")
  528. a.Data =array(b, c) 'b与c为二维数组
  529. a.TitleFirstLine = array(false, true) '首行是否为标题行
  530. a.Create()
  531. response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")
  532. Set a=nothing


  533. '使用示例四        需要数据库支持
  534. 'Dim rs
  535. 'Set rs=server.CreateObject("Adodb.RecordSet")
  536. 'rs.open "Select id, classid, className from [class] ",conn, 1, 1
  537. 'Set a=new CreateExcel
  538. 'a.SavePath="a"
  539. 'a.AddDBData rs, "序号,类别序号,类别名称", "工作簿名称", "类别表", false
  540. 'a.Create()
  541. 'response.Write("生成"& a.SavePath &" 使用了 "& a.GetTime(a.UsedTime) &"<br>")
  542. 'Set a=nothing
  543. 'rs.close
  544. 'Set rs=nothing
  545. %>
复制代码
已有 1 人评分威望 收起 理由
kuhanzhu + 1 原创内容,谢谢分享。

总评分: 威望 + 1   查看全部评分

快.简.有效http://www.lc00.com
西部数码顶级域名注册商39元抢注!
帖子
589
体力
1395
威望
0
发表于 2009-6-27 14:56:44 |显示全部楼层
顶一下吧。现在bi就是这样。好东西没人看。
好用的分页类:http://jorkin.me
租服务器,上51IDC | [长沙]招聘:PHP经理10K/WEB前端6K/PHP开发6K

使用道具 举报

yudi 

雨滴

银牌会员

帖子
390
体力
2106
威望
0
居住地
甘肃省 兰州市
发表于 2009-6-27 15:56:26 |显示全部楼层
不错,挺好的,值得学习,顶一下
只有累才证明自己活着!

使用道具 举报

苦寒竹

管理员

帖子
19771
体力
17927
威望
23
居住地
浙江省 金华市
发表于 2009-6-27 15:58:35 |显示全部楼层

回复 2# jorkin2000 的帖子

有见解可以说一下。也可以写一下学习心得。
回复数说明不了什么。
搞IT的穷秀才。

使用道具 举报

帖子
23
体力
187
威望
0
发表于 2009-9-16 14:23:02 |显示全部楼层
原来以为操作excle很简单,看到这个长见识了

使用道具 举报

ugxxx 
帖子
326
体力
701
威望
0
居住地
广东省 广州市
发表于 2009-9-19 17:42:44 |显示全部楼层
有空,改天把它翻译为Javascript版..
谢谢楼主分享.
<阿龍> donaldsu.cn

使用道具 举报

xxcss 
帖子
388
体力
862
威望
0
居住地
湖北省 潜江市
发表于 2009-9-19 18:34:22 |显示全部楼层
加点入口函数说明吗 好东西是要顶的

使用道具 举报

帖子
54
体力
243
威望
0
居住地
江苏省 苏州市
发表于 2009-9-21 00:24:20 |显示全部楼层
收藏一下

使用道具 举报

uuico 
帖子
81
体力
419
威望
0
居住地
山东省 聊城市
发表于 2010-1-2 10:38:18 |显示全部楼层
学习一下
学习学习

使用道具 举报

帖子
464
体力
2378
威望
0
居住地
广东省 深圳市
发表于 2010-1-3 16:44:42 |显示全部楼层
释放资源是个问题,.NET通过终止进程,不知道你这个能做到不。

使用道具 举报

二分之一

钻石会员 手机认证 

帖子
2205
体力
8414
威望
0
居住地
天津市 北辰区
发表于 2010-1-3 19:19:03 |显示全部楼层
我执行不了。。
轻松熊rilakkuama很萌哦~

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

Archiver|手机版|安久科技提供CDN|blueidea.com ( 京ICP备05002321号 )  

GMT+8, 2012-2-12 07:32 , Processed in 0.088669 second(s), 9 queries , Gzip On, Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部