posts - 56, comments - 54, trackbacks - 0, articles - 4
             ::  ::  :: 聯(lián)系 :: 聚合  :: 管理

          ??? Dim xlApp As Excel.Application
          ??? Dim xlBook As Excel.Workbook
          ??? Dim xlSheet As Excel.Worksheet
          ????
          ??? Set xlApp = CreateObject("Excel.Application") '創(chuàng)建EXCEL對象
          ??? Set xlBook = xlApp.Workbooks.Add??? 'xlApp.Workbooks.Open("文件名") '打開已經(jīng)存在的EXCEL工件簿文件
          ??? xlApp.Visible = False '設(shè)置EXCEL對象可見(或不可見)
          ??? Set xlSheet = xlBook.Worksheets(1) '設(shè)置活動(dòng)工作表
          ??? xlSheet.Activate
          ??? xlSheet.Range("C3").Value = "1"
          ??? xlSheet.Cells(1, 1) = "test中文" '給單元格(row,col)賦值
          ???
          ??? ' 畫邊框線
          ??? xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(2, 2)).Borders.LineStyle = xlContinuous
          ???
          ??? xlSheet.Rows(1).HorizontalAlignment = xlVAlignCenter '左右居中
          ??? xlSheet.Rows(1).VerticalAlignment = xlVAlignCenter '上下居中

          ????xlSheet.Cells(iStartRow + idx, 2).HorizontalAlignment = xlVAlignCenter '左右居中
          ????
          ??? '設(shè)置指定列的寬度(單位:字符個(gè)數(shù))
          ??? xlApp.ActiveSheet.Columns(1).ColumnWidth = 15

          ??? '設(shè)置指定行的高度(單位:磅)
          ??? xlApp.ActiveSheet.Rows(1).RowHeight = 1 / 0.035
          ???
          ??? '設(shè)置字體
          ??? 'xlApp.ActiveSheet.Cells(1, 1).Font.Name = "黑體"

          ??? '設(shè)置字體大小
          ??? xlApp.ActiveSheet.Cells(1, 1).Font.Size = 25
          ???
          ??? '設(shè)置整列字體為粗體
          ??? xlApp.ActiveSheet.Columns(1).Font.Bold = True
          ???
          ??? 'xlBook.SaveAs ("C:\Case1.xls")
          ???
          ??? 'xlSheet.PrintPreview (True)
          ???
          ??? xlApp.Visible = True '顯示文件
          ???
          ??? 'xlSheet.PrintOut '打印工作表

          ??? If Not (xlApp Is Nothing) Then
          ????????
          ??????? xlBook.Close (True) '關(guān)閉工作簿
          ???????
          ??????? xlApp.Quit '必須結(jié)束EXCEL對象
          ??????? Set xlApp = Nothing '釋放xlApp對象
          ??? End If


          評(píng)論

          # re: VB中動(dòng)態(tài)生成Excel文件  回復(fù)  更多評(píng)論   

          2014-09-15 10:06 by rwer
          wrwer
          主站蜘蛛池模板: 日喀则市| 阿拉善右旗| 恩平市| 宁蒗| 清涧县| 阳谷县| 安国市| 娱乐| 宿州市| 安多县| 晋城| 三门县| 老河口市| 镇赉县| 肥城市| 富顺县| 青河县| 西贡区| 沁水县| 岱山县| 余干县| 紫金县| 汉川市| 金门县| 东宁县| 扶余县| 镇宁| 和平县| 古田县| 大宁县| 墨竹工卡县| 江达县| 海宁市| 西安市| 新巴尔虎右旗| 天津市| 伊川县| 昭觉县| 新和县| 康平县| 奉新县|