PowerDesigner生成Excel(实体+数据库版)

  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. '* Version:  1.0  
  10. '******************************************************************************  
  11. Option Explicit  
  12.    Dim rowsNum  
  13.    rowsNum = 0  
  14. '-----------------------------------------------------------------------------  
  15. ' Main function  
  16. '-----------------------------------------------------------------------------  
  17. ' Get the current active model  
  18. Dim Model  
  19. Set Model = ActiveModel  
  20. If (Model Is NothingOr (Not Model.IsKindOf(PdPDM.cls_Model)) Then  
  21.   MsgBox "The current model is not an PDM model."  
  22. Else  
  23.  ' Get the tables collection  
  24.  '创建EXCEL APP  
  25.  dim beginrow  
  26.  DIM EXCEL, SHEET  
  27.  set EXCEL = CREATEOBJECT("Excel.Application")  
  28.  EXCEL.workbooks.add(-4167)'添加工作表  
  29.  EXCEL.workbooks(1).sheets(1).name ="test"  
  30.  set sheet = EXCEL.workbooks(1).sheets("test")  
  31.    
  32.  ShowProperties Model, SHEET  
  33.  EXCEL.visible = true  
  34.  '设置列宽和自动换行  
  35.  sheet.Columns(1).ColumnWidth = 20   
  36.  sheet.Columns(2).ColumnWidth = 40   
  37.  sheet.Columns(4).ColumnWidth = 20   
  38.  sheet.Columns(5).ColumnWidth = 20   
  39.  sheet.Columns(6).ColumnWidth = 15   
  40.  sheet.Columns(1).WrapText =true  
  41.  sheet.Columns(2).WrapText =true  
  42.  sheet.Columns(4).WrapText =true  
  43.  End If  
  44. '-----------------------------------------------------------------------------  
  45. ' Show properties of tables  
  46. '-----------------------------------------------------------------------------  
  47. Sub ShowProperties(mdl, sheet)  
  48.    ' Show tables of the current model/package  
  49.    rowsNum=0  
  50.    beginrow = rowsNum+1  
  51.    ' For each table  
  52.    output "begin"  
  53.    Dim tab  
  54.    For Each tab In mdl.tables  
  55.       ShowTable tab,sheet  
  56.    Next  
  57.    if mdl.tables.count > 0 then  
  58.         sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group  
  59.    end if  
  60.    output "end"  
  61. End Sub  
  62. '-----------------------------------------------------------------------------  
  63. ' Show table properties  
  64. '-----------------------------------------------------------------------------  
  65. Sub ShowTable(tab, sheet)  
  66.    If IsObject(tab) Then  
  67.      Dim rangFlag  
  68.      rowsNum = rowsNum + 1  
  69.       ' Show properties  
  70.       Output "================================"  
  71.       sheet.cells(rowsNum, 1) = "实体名"  
  72.       sheet.cells(rowsNum, 2) =tab.name  
  73.       sheet.cells(rowsNum, 3) = ""  
  74.       sheet.cells(rowsNum, 4) = "表名"  
  75.       sheet.cells(rowsNum, 5) = tab.code  
  76.       sheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).Merge  
  77.       rowsNum = rowsNum + 1  
  78.       sheet.cells(rowsNum, 1) = "属性名"  
  79.       sheet.cells(rowsNum, 2) = "说明"  
  80.       sheet.cells(rowsNum, 3) = ""  
  81.       sheet.cells(rowsNum, 4) = "字段中文名"  
  82.       sheet.cells(rowsNum, 5) = "字段名"  
  83.       sheet.cells(rowsNum, 6) = "字段类型"  
  84.       '设置边框  
  85.       sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Borders.LineStyle = "1"  
  86.       sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Borders.LineStyle = "1"  
  87. Dim col ' running column  
  88. Dim colsNum  
  89. colsNum = 0  
  90.       for each col in tab.columns  
  91.         rowsNum = rowsNum + 1  
  92.         colsNum = colsNum + 1  
  93.       sheet.cells(rowsNum, 1) = col.name  
  94.       sheet.cells(rowsNum, 2) = col.comment  
  95.         sheet.cells(rowsNum, 3) = ""  
  96.       sheet.cells(rowsNum, 4) = col.name  
  97.       sheet.cells(rowsNum, 5) = col.code  
  98.       sheet.cells(rowsNum, 6) = col.datatype  
  99.       next  
  100.       sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,2)).Borders.LineStyle = "2"         
  101.       sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,6)).Borders.LineStyle = "2"  
  102.       rowsNum = rowsNum + 1  
  103.         
  104.       Output "FullDescription: "       + tab.Name  
  105.    End If  
  106. End Sub  

猜你喜欢

转载自blog.csdn.net/leejin_521/article/details/50627708