数据库表结构转成设计书,PowerDesigner 表格导出为excel

Posted shangshen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库表结构转成设计书,PowerDesigner 表格导出为excel相关的知识,希望对你有一定的参考价值。

数据库中的表导入到PowerDesigner中并转为excel文档

1、打开PowerDesigner12,在菜单中按照如下方式进行操作

   file->Reverse Engineer->DataBase

   点击后,弹出 New Physical Data Model 的对话框

 

2、在General选项卡中

    Model name:模板名字,自己命名。

    DMBMS    :根据需要选择,我选择的是ORACLEVersion 10g

点确定后弹出 Database Reverse Engineering Option 对话框

 

3  Selection选项卡中,选中Using a data source选项

   注意如果是第一次导入数据,需要你先自己配制ODBC数据源,方法如下:

1)点击 下面 右侧的数据库 连接按钮,弹出 Connect to a Data Source 的对话框

2)选中 ODBC machine data source 选项,点击 Modify按钮右边的 Configure 按钮   弹出Configure Data Connections

 

3)在 ODBC Machine Data Sources选项卡   下面的工具栏中点击 第二个 数据库 配置按钮(Add Data Source(Ctrl+N)) 弹出创建新数据源窗口 ,选择文件数据源,    选择相应的数据源驱动程序(我选Oracle),点下一步(Modify),给数据源起个名字,选择服务器,下一步,输入相应的密码 

 

配置完毕 后 点击确定

 

4,选择刚刚配置的数据源,输入相应的用户名和密码   即可。 

 

=====得到PDM物理设计说明书

选中tables
ctrl + shift +x 然后运行脚本

技术分享图片
  1 ******************************************************************************
  2 Option Explicit
  3    Dim rowsNum
  4    rowsNum = 0
  5 -----------------------------------------------------------------------------
  6  Main function
  7 -----------------------------------------------------------------------------
  8  Get the current active model
  9     Dim Model
 10     Set Model = ActiveModel
 11     If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then
 12        MsgBox "The current model is not an PDM model."
 13     Else
 14        Get the tables collection
 15       创建EXCEL APP
 16       dim beginrow
 17       DIM EXCEL, SHEET, SHEETLIST
 18       set EXCEL = CREATEOBJECT("Excel.Application")
 19       EXCEL.workbooks.add(-4167)添加工作表
 20       EXCEL.workbooks(1).sheets(1).name ="表结构"
 21       set SHEET = EXCEL.workbooks(1).sheets("表结构")
 22       
 23       EXCEL.workbooks(1).sheets.add
 24       EXCEL.workbooks(1).sheets(1).name ="目录"
 25       set SHEETLIST = EXCEL.workbooks(1).sheets("目录")
 26       ShowTableList Model,SHEETLIST
 27 
 28       ShowProperties Model, SHEET,SHEETLIST
 29       
 30       
 31       EXCEL.workbooks(1).Sheets(2).Select
 32       EXCEL.visible = true
 33       设置列宽和自动换行
 34       sheet.Columns(1).ColumnWidth = 20 
 35       sheet.Columns(2).ColumnWidth = 20 
 36       sheet.Columns(3).ColumnWidth = 20 
 37       sheet.Columns(4).ColumnWidth = 40 
 38       sheet.Columns(5).ColumnWidth = 10 
 39       sheet.Columns(6).ColumnWidth = 10 
 40       sheet.Columns(1).WrapText =true
 41       sheet.Columns(2).WrapText =true
 42       sheet.Columns(4).WrapText =true
 43       不显示网格线
 44       EXCEL.ActiveWindow.DisplayGridlines = False
 45       
 46       
 47  End If
 48 -----------------------------------------------------------------------------
 49  Show properties of tables
 50 -----------------------------------------------------------------------------
 51 Sub ShowProperties(mdl, sheet,SheetList)
 52     Show tables of the current model/package
 53    rowsNum=0
 54    beginrow = rowsNum+1
 55    Dim rowIndex 
 56    rowIndex=3
 57     For each table
 58    output "begin"
 59    Dim tab
 60    For Each tab In mdl.tables
 61       ShowTable tab,sheet,rowIndex,sheetList
 62       rowIndex = rowIndex +1
 63    Next
 64    if mdl.tables.count > 0 then
 65         sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group
 66    end if
 67    output "end"
 68 End Sub
 69 -----------------------------------------------------------------------------
 70  Show table properties
 71 -----------------------------------------------------------------------------
 72 Sub ShowTable(tab, sheet,rowIndex,sheetList)
 73    If IsObject(tab) Then
 74      Dim rangFlag
 75      rowsNum = rowsNum + 1
 76        Show properties
 77       Output "================================"
 78       sheet.cells(rowsNum, 1) =tab.name
 79       sheet.cells(rowsNum, 1).HorizontalAlignment=3
 80       sheet.cells(rowsNum, 2) = tab.code
 81       sheet.cells(rowsNum, 5).HorizontalAlignment=3
 82       sheet.cells(rowsNum, 6) = ""
 83       sheet.cells(rowsNum, 7) = "表说明"
 84       sheet.cells(rowsNum, 3) = tab.comment
 85       sheet.cells(rowsNum, 8).HorizontalAlignment=3
 86       sheet.Range(sheet.cells(rowsNum, 3),sheet.cells(rowsNum, 7)).Merge
 87       设置超链接,从目录点击表名去查看表结构
 88       字段中文名    字段英文名    字段类型    注释    是否主键    是否非空    默认值
 89       sheetList.Hyperlinks.Add sheetList.cells(rowIndex,2), "","表结构"&"!B"&rowsNum
 90       rowsNum = rowsNum + 1
 91       sheet.cells(rowsNum, 1) = "字段中文名"
 92       sheet.cells(rowsNum, 2) = "字段英文名"
 93       sheet.cells(rowsNum, 3) = "字段类型"
 94       sheet.cells(rowsNum, 4) = "注释"
 95       sheet.cells(rowsNum, 5) = "是否主键"
 96       sheet.cells(rowsNum, 6) = "是否非空"
 97       sheet.cells(rowsNum, 7) = "默认值"
 98       设置边框
 99       sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Borders.LineStyle = "1"
100       sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"
101       字体为10号
102       sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Font.Size=10
103             Dim col  running column
104             Dim colsNum
105             colsNum = 0
106       for each col in tab.columns
107         rowsNum = rowsNum + 1
108         colsNum = colsNum + 1
109           sheet.cells(rowsNum, 1) = col.name
110         sheet.cells(rowsNum, 3) = ""
111           sheet.cells(rowsNum, 4) = col.name
112           sheet.cells(rowsNum, 2) = col.code
113           sheet.cells(rowsNum, 3) = col.datatype
114         sheet.cells(rowsNum, 4) = col.comment
115           If col.Primary = true Then
116         sheet.cells(rowsNum, 5) = "Y" 
117         Else
118         sheet.cells(rowsNum, 5) = " " 
119         End If
120         If col.Mandatory = true Then
121         sheet.cells(rowsNum, 6) = "Y" 
122         Else
123         sheet.cells(rowsNum, 6) = " " 
124         End If
125         sheet.cells(rowsNum, 7) =  col.defaultvalue
126       next
127       sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Borders.LineStyle = "3"       
128       sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,9)).Borders.LineStyle = "3"
129       sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Font.Size = 10
130       rowsNum = rowsNum + 2
131       
132       Output "FullDescription: "       + tab.Name
133    End If
134    
135 End Sub
136 -----------------------------------------------------------------------------
137  Show List Of Table
138 -----------------------------------------------------------------------------
139 Sub ShowTableList(mdl, SheetList)
140     Show tables of the current model/package
141    Dim rowsNo
142    rowsNo=1
143     For each table
144    output "begin"
145    SheetList.cells(rowsNo, 1) = "主题"
146    SheetList.cells(rowsNo, 2) = "表中文名"
147    SheetList.cells(rowsNo, 3) = "表英文名"
148    SheetList.cells(rowsNo, 4) = "表说明"
149    rowsNo = rowsNo + 1
150    SheetList.cells(rowsNo, 1) = mdl.name
151    Dim tab
152    For Each tab In mdl.tables
153      If IsObject(tab) Then
154          rowsNo = rowsNo + 1
155       SheetList.cells(rowsNo, 1) = ""
156       SheetList.cells(rowsNo, 2) = tab.name
157       SheetList.cells(rowsNo, 3) = tab.code
158       SheetList.cells(rowsNo, 4) = tab.comment
159      End If
160    Next
161     SheetList.Columns(1).ColumnWidth = 20 
162       SheetList.Columns(2).ColumnWidth = 20 
163       SheetList.Columns(3).ColumnWidth = 30 
164      SheetList.Columns(4).ColumnWidth = 60 
165    output "end"
166 End Sub
View Code

 

该代码为宏代码

 

参考:

https://blog.csdn.net/a824444865/article/details/50072655

https://www.cnblogs.com/gaocong/p/6553080.html


以上是关于数据库表结构转成设计书,PowerDesigner 表格导出为excel的主要内容,如果未能解决你的问题,请参考以下文章

powerdesigner 连接 Oracle ,并将表结构导入到powerdesigner中

导出数据库表为world文档说明,已经PowerDesigner导出表结构pdm设计文档

反向读取Mysql数据库表结构到PowerDesigner中

PowerDesigner工具

通过Excel生成PowerDesigner表结构设计

通过Excel生成PowerDesigner表结构设计