PowerDesigner生成Excel版本的数据库文件

要把数据库设计转成一个excel版本的,百度出来一个脚本文件,很好用发现,留个纪念

在pd中,shift+ctrl+X,打开脚本运行,脚本如下,附件也留了一份:

[vb]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  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  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值