解决问题(有mysql数据库数据表想要将表导入到PowerDesigner 或导出Excel数据字典)
一、下载工具
1、工具PowerDesigner 百度自行下载安装
2、mysql-connector-odbc 下载链接: https://pan.baidu.com/s/1cjb73f3GvkkMFAzZKi85xA 提取码: u5ih
二、mysql数据库数据表想要将表导入到PowerDesigner
1、创建一个新的PowerDesigner
(一)创建逆向工程
(二)选择数据库类型我们这里是mysql
(三)连接我们的数据库 点击连接按钮
(四)点击配置
(五)点击新增一个数据连接 点击确定
(六)选择用户数据源 下一步
(七)选择mysql 下一步
(八)点击完成
(九)填写用户名密码 第一项创建数据源名称,第二项创建数据源描述,第三项创建数据源的IP地址 端口号,第四项名称,第五项密码,
最后一项想要导的数据库这里可以不选 点击Test成功后点击ok 就会出现一个刚创建的数据源点击确定
(十)选择刚刚创建的数据源 连接确定
(十一)选择要导的库(如要导出所有表可滑到最上面可选择All users)点击ok再点击ok
(十二)mysql数据库数据表想要将表导入到PowerDesigner(完成)
三、导出Excel数据字典
1、选中想要导出Excel数据字典的表 按ctrl + shift +x 然后运行脚本 大功告成
'******************************************************************************
Option Explicit
Dim rowsNum
rowsNum= 0
'-----------------------------------------------------------------------------' Main function'-----------------------------------------------------------------------------' Get the current active model
Dim Model
Set Model=ActiveModel
If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then
MsgBox"The current model is not an PDM model."Else' Get the tables collection
'创建EXCEL APP
dim beginrow
DIM EXCEL, SHEET, SHEETLIST
set EXCEL= CREATEOBJECT("Excel.Application")
EXCEL.workbooks.add(-4167)'添加工作表
EXCEL.workbooks(1).sheets(1).name ="表结构"set SHEET= EXCEL.workbooks(1).sheets("表结构")
EXCEL.workbooks(1).sheets.add
EXCEL.workbooks(1).sheets(1).name ="目录"set SHEETLIST= EXCEL.workbooks(1).sheets("目录")
ShowTableList Model,SHEETLIST
ShowProperties Model, SHEET,SHEETLIST
EXCEL.workbooks(1).Sheets(2).Select
EXCEL.visible= true
'设置列宽和自动换行
sheet.Columns(1).ColumnWidth = 20sheet.Columns(2).ColumnWidth = 20sheet.Columns(3).ColumnWidth = 20sheet.Columns(4).ColumnWidth = 40sheet.Columns(5).ColumnWidth = 10sheet.Columns(6).ColumnWidth = 10sheet.Columns(1).WrapText =truesheet.Columns(2).WrapText =truesheet.Columns(4).WrapText =true
'不显示网格线
EXCEL.ActiveWindow.DisplayGridlines =False
End If'-----------------------------------------------------------------------------' Show properties of tables'-----------------------------------------------------------------------------
Sub ShowProperties(mdl, sheet,SheetList)' Show tables of the current model/package
rowsNum=0beginrow= rowsNum+1Dim rowIndex
rowIndex=3
' For each table
output "begin"Dim tab
For Each tab In mdl.tables
ShowTable tab,sheet,rowIndex,sheetList
rowIndex= rowIndex +1Nextif mdl.tables.count > 0then
sheet.Range("A" & beginrow + 1 & ":A" &rowsNum).Rows.Group
endifoutput"end"End Sub'-----------------------------------------------------------------------------' Show table properties'-----------------------------------------------------------------------------
Sub ShowTable(tab, sheet,rowIndex,sheetList)
If IsObject(tab) Then
Dim rangFlag
rowsNum= rowsNum + 1
' Show properties
Output "================================"sheet.cells(rowsNum,1) =tab.name
sheet.cells(rowsNum,1).HorizontalAlignment=3sheet.cells(rowsNum,2) =tab.code'sheet.cells(rowsNum, 5).HorizontalAlignment=3
'sheet.cells(rowsNum, 6) = ""
'sheet.cells(rowsNum, 7) = "表说明"
sheet.cells(rowsNum, 3) =tab.comment'sheet.cells(rowsNum, 8).HorizontalAlignment=3
sheet.Range(sheet.cells(rowsNum, 3),sheet.cells(rowsNum, 7)).Merge'设置超链接,从目录点击表名去查看表结构
'字段中文名 字段英文名 字段类型 注释 是否主键 是否非空 默认值
sheetList.Hyperlinks.Add sheetList.cells(rowIndex,2), "","表结构"&"!B"&rowsNum
rowsNum= rowsNum + 1sheet.cells(rowsNum,1) = "字段中文名"sheet.cells(rowsNum,2) = "字段英文名"sheet.cells(rowsNum,3) = "字段类型"sheet.cells(rowsNum,4) = "注释"sheet.cells(rowsNum,5) = "是否主键"sheet.cells(rowsNum,6) = "是否非空"sheet.cells(rowsNum,7) = "默认值"
'设置边框
sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Borders.LineStyle = "1"
'sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"
'字体为10号
sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Font.Size=10Dim col' running column
Dim colsNum
colsNum= 0
foreach col in tab.columns
rowsNum= rowsNum + 1colsNum= colsNum + 1sheet.cells(rowsNum,1) =col.name'sheet.cells(rowsNum, 3) = ""
'sheet.cells(rowsNum, 4) = col.name
sheet.cells(rowsNum, 2) =col.code
sheet.cells(rowsNum,3) =col.datatype
sheet.cells(rowsNum,4) =col.comment
If col.Primary= trueThen
sheet.cells(rowsNum,5) = "Y"Else
sheet.cells(rowsNum,5) = " "End If
If col.Mandatory= trueThen
sheet.cells(rowsNum,6) = "Y"Else
sheet.cells(rowsNum,6) = " "End If
sheet.cells(rowsNum,7) =col.defaultvalue
next
sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Borders.LineStyle = "3"
'sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,9)).Borders.LineStyle = "3"
sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Font.Size = 10rowsNum= rowsNum + 2Output"FullDescription: " +tab.Name
End If
End Sub'-----------------------------------------------------------------------------' Show List Of Table'-----------------------------------------------------------------------------
Sub ShowTableList(mdl, SheetList)' Show tables of the current model/package
Dim rowsNo
rowsNo=1
' For each table
output "begin"SheetList.cells(rowsNo,1) = "主题"SheetList.cells(rowsNo,2) = "表中文名"SheetList.cells(rowsNo,3) = "表英文名"SheetList.cells(rowsNo,4) = "表说明"rowsNo= rowsNo + 1SheetList.cells(rowsNo,1) =mdl.name
Dim tab
For Each tab In mdl.tables
If IsObject(tab) Then
rowsNo= rowsNo + 1SheetList.cells(rowsNo,1) = ""SheetList.cells(rowsNo,2) =tab.name
SheetList.cells(rowsNo,3) =tab.code
SheetList.cells(rowsNo,4) =tab.comment
End If
Next
SheetList.Columns(1).ColumnWidth = 20SheetList.Columns(2).ColumnWidth = 20SheetList.Columns(3).ColumnWidth = 30SheetList.Columns(4).ColumnWidth = 60output"end"End Sub