夢(mèng)幻之旅

          DEBUG - 天道酬勤

             :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評(píng)論 :: 0 Trackbacks
            1 '******************************************************************************
            2 '* File:     pdm2excel.txt
            3 '* Title:    pdm export to excel
            4 '* Purpose:  To export the tables and columns to Excel
            5 '* Model:    Physical Data Model
            6 '* Objects:  Table, Column, View
            7 '* Author:   ziyan
            8 '* Created:  2012-05-03
            9 '*Modifier:  Hui Wanpeng 2014/07/04
           10 '* Version:  1.0
           11 '******************************************************************************
           12 Option Explicit
           13  Dim rowsNum
           14  rowsNum = 0
           15 
           16 '-----------------------------------------------------------------------------
           17 ' Main function
           18 '-----------------------------------------------------------------------------
           19 ' Get the current active model
           20 
           21 Dim Model
           22 Set Model = ActiveModel
           23 If (Model Is NothingOr (Not Model.IsKindOf(PdPDM.cls_Model)) Then
           24     MsgBox "The current model is not an PDM model."
           25 Else
           26      ' Get the tables collection
           27      '創(chuàng)建EXCEL APP
           28      Dim beginrow
           29      Dim EXCEL, SHEET
           30      set EXCEL = CREATEOBJECT("Excel.Application")
           31      EXCEL.workbooks.add(-4167)'添加工作表
           32      EXCEL.workbooks(1).sheets(1).name ="test"
           33      set sheet = EXCEL.workbooks(1).sheets("test")
           34 
           35     ShowProperties Model, SHEET
           36     EXCEL.visible = true
           37 
           38     '設(shè)置列寬和自動(dòng)換行
           39     sheet.Columns(1).ColumnWidth = 20 
           40      sheet.Columns(2).ColumnWidth = 40 
           41      sheet.Columns(4).ColumnWidth = 20 
           42      sheet.Columns(5).ColumnWidth = 20 
           43      sheet.Columns(6).ColumnWidth = 15 
           44      sheet.Columns(1).WrapText =true
           45      sheet.Columns(2).WrapText =true
           46      sheet.Columns(4).WrapText =true
           47  End If
           48 
           49 '-----------------------------------------------------------------------------
           50 ' Show properties of tables
           51 '-----------------------------------------------------------------------------
           52 Sub ShowProperties(mdl, sheet)
           53     ' Show tables of the current model/package
           54     rowsNum=0
           55     beginrow = rowsNum+1
           56 
           57     ' For each table
           58     output "begin"
           59 
           60     Dim tab
           61     For Each tab In mdl.tables
           62         ShowTable tab,sheet
           63     Next
           64 
           65     if mdl.tables.count > 0 then
           66         sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group
           67     end if
           68     output "end"
           69 End Sub
           70 
           71 '-----------------------------------------------------------------------------
           72 ' Show table properties
           73 '-----------------------------------------------------------------------------
           74 Sub ShowTable(tab, sheet)
           75     If IsObject(tab) Then
           76     Dim rangFlag
           77     rowsNum = rowsNum + 1
           78 
           79      ' Show properties
           80     Output "================================"
           81     sheet.cells(rowsNum, 1) = "實(shí)體名"
           82     sheet.cells(rowsNum, 2) =tab.name
           83     sheet.cells(rowsNum, 3) = ""
           84     sheet.cells(rowsNum, 4) = "表名"
           85     sheet.cells(rowsNum, 5) = tab.code
           86     sheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).Merge
           87     rowsNum = rowsNum + 1
           88     sheet.cells(rowsNum, 1) = "屬性名"
           89     sheet.cells(rowsNum, 2) = "說(shuō)明"
           90     sheet.cells(rowsNum, 3) = ""
           91     sheet.cells(rowsNum, 4) = "字段中文名"
           92     sheet.cells(rowsNum, 5) = "字段名"
           93     sheet.cells(rowsNum, 6) = "字段類(lèi)型"
           94 
           95     '設(shè)置邊框
           96     sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Borders.LineStyle = "1"
           97     sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Interior.ColorIndex = 20
           98     sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Borders.LineStyle = "1"
           99     sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Interior.ColorIndex = 20
          100 
          101     Dim col ' running column
          102     Dim colsNum
          103     colsNum = 0
          104     for each col in tab.columns
          105         rowsNum = rowsNum + 1
          106         colsNum = colsNum + 1
          107         sheet.cells(rowsNum, 1) = col.name
          108         sheet.cells(rowsNum, 2) = col.comment
          109         sheet.cells(rowsNum, 3) = ""
          110         'sheet.cells(rowsNum, 4) = col.name
          111         sheet.cells(rowsNum, 4) = col.comment
          112         sheet.cells(rowsNum, 5) = col.code
          113         sheet.cells(rowsNum, 6) = col.datatype
          114     next
          115       sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,2)).Borders.LineStyle = "2"  
          116       sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,6)).Borders.LineStyle = "2"
          117       rowsNum = rowsNum + 1
          118       Output "FullDescription: "       + tab.Name
          119    End If
          120 End Sub
          121 
          posted on 2014-07-06 21:07 HUIKK 閱讀(377) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 丹寨县| 福清市| 寻乌县| 渝北区| 台山市| 惠安县| 丰顺县| 铁岭市| 彭阳县| 万年县| 大田县| 韶山市| 荃湾区| 铁岭市| 和静县| 景泰县| 长兴县| 芜湖市| 桃园市| 伊金霍洛旗| 盘山县| 当雄县| 遵义市| 海门市| 秦安县| 晴隆县| 交口县| 天长市| 曲阜市| 顺平县| 开阳县| 唐海县| 利辛县| 安化县| 历史| 北安市| 石狮市| 淄博市| 即墨市| 双桥区| 饶平县|