posts - 56, comments - 54, trackbacks - 0, articles - 4
             ::  ::  :: 聯系 :: 聚合  :: 管理

          VB中動態生成Excel文件

          Posted on 2006-05-24 11:28 Terry的Blog 閱讀(2642) 評論(1)  編輯  收藏 所屬分類: 其他(工具軟件...)

          ??? Dim xlApp As Excel.Application
          ??? Dim xlBook As Excel.Workbook
          ??? Dim xlSheet As Excel.Worksheet
          ????
          ??? Set xlApp = CreateObject("Excel.Application") '創建EXCEL對象
          ??? Set xlBook = xlApp.Workbooks.Add??? 'xlApp.Workbooks.Open("文件名") '打開已經存在的EXCEL工件簿文件
          ??? xlApp.Visible = False '設置EXCEL對象可見(或不可見)
          ??? Set xlSheet = xlBook.Worksheets(1) '設置活動工作表
          ??? 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 '左右居中
          ????
          ??? '設置指定列的寬度(單位:字符個數)
          ??? xlApp.ActiveSheet.Columns(1).ColumnWidth = 15

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

          ??? '設置字體大小
          ??? xlApp.ActiveSheet.Cells(1, 1).Font.Size = 25
          ???
          ??? '設置整列字體為粗體
          ??? 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) '關閉工作簿
          ???????
          ??????? xlApp.Quit '必須結束EXCEL對象
          ??????? Set xlApp = Nothing '釋放xlApp對象
          ??? End If


          評論

          # re: VB中動態生成Excel文件  回復  更多評論   

          2014-09-15 10:06 by rwer
          wrwer
          主站蜘蛛池模板: 韶山市| 白玉县| 泸溪县| 固原市| 郸城县| 合水县| 龙川县| 新竹县| 锡林郭勒盟| 波密县| 鸡东县| 如皋市| 兴国县| 漠河县| 怀远县| 泸州市| 秭归县| 虹口区| 辛集市| 玉田县| 合作市| 梁河县| 武穴市| 芜湖市| 聂荣县| 临邑县| 南丰县| 乳源| 仪征市| 阜新| 福安市| 施甸县| 万荣县| 修水县| 大理市| 榆林市| 壶关县| 开原市| 长宁区| 诸城市| 永泰县|