powerdesigner连接postgresql数据库生成pdm及word文档(五)

1、准备软件:

powerdesigner165与postgresql的驱动:psqlodbc_11_01_0000

2、安装并破解完成powerdesigner165

参看链接:https://www.cnblogs.com/zksfyz/p/8966594.html

3、安装postgresql的驱动:psqlodbc_11_01_0000

参看链接:https://blog.51cto.com/fengyuzaitu/2438827

4、配置postgresql的驱动

搜索开始栏ODBC,用户DSN,添加驱动

参看链接:https://blog.51cto.com/fengyuzaitu/2438827

5、powerdesigner连接数据库

搜索关键词:

powerdesigner连接postgresql数据库生成pdm及word文档
powerdesigner导出word文档

(1)创建model

(2)连接数据库

第一步:

第二步:

 第三步:

 第四步:

第五步:

 第六步:

(3)model连接数据库生成pdm

选中新创建的model,

Database–>Update Model from Database…

(4)创建word模板

一、创建导出模版

1.Report下点击Report Templates...

2.点击新建

3.配置模版:模版名,简体中文,物理模型

4.配置模版显示项

Available items -- List of Tables 双击移动至右侧,用于显示全部表信息

Available items -- Table -- List of Table Columns 双击移动至右侧,用于显示单表信息

List of Table Columns -- 右键 -- Layout... -- 自定义要显示的字段和宽度

一般选择以下几项:是否主键、字段名、数据类型、注释

5.配置模版显示风格

双击节点可以编辑中文描述

模版名称 -- 右键 -- Header/Footer... -- 自定义页眉页脚

这里不需要,直接删除

6.保存模版

建议将自己创建.rtp模版文件,保存到PowerDesigner默认模版目录中:PowerDesigner 16.5Resource FilesReport Templates

二、根据模版生成数据库文档

1.导入sql反向生成物理模型

根据数据库选择,我用的是mysql

添加.sql文件,点击确定

成功反向生成物理模型

2.Report下点击Generate Report...

找到刚刚保存的模版,并生成RTF

3.rtf转doc或docx

打开生成rtf文件,点击另存为,选择文件类型*.doc或者*.docx

参看链接:

https://blog.csdn.net/move_on_on/article/details/89175490

https://blog.csdn.net/github_39325328/article/details/80902471

6、修改pdm文档的表name为中文名(均需要保证数据库有注释comment)

PowerDesigner中NAME和COMMENT的互相转换,需要执行语句

由于PDM 的表中 Name 会默认=Code 所以很不方便, 所以需要将 StereoType 显示到表的外面来

打开[工具]->[显示属性](英文:Display Preferences) ->Content->Table->右边面板Columns框中 勾选: StereoType ,这样再在 StereoType中填入code字段相同内容就会显示在图形界面上了

使用说明: 在【Tools】-【Execute Commands】-【Edit/Run Script】 下。输入下面你要选择的语句即可,也可以保存起来,以便下次使用,后缀为.vbs。

 需要注意的问题是:运行语句时必须在Module模式下,如果是导出报表时执行会出现错误提示。

1.Name转到Comment注释字段。一般情况下只填写NAME,COMMENT可以运行语句自动生成。

将该语句保存为name2comment.vbs

'把pd中那么name想自动添加到comment里面
'如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失.

Option   Explicit 
ValidationMode   =   True 
InteractiveMode   =   im_Batch 

Dim   mdl   '   the   current   model 

'   get   the   current   active   model 
Set   mdl   =   ActiveModel 
If   (mdl   Is   Nothing)   Then 
      MsgBox   "There   is   no   current   Model " 
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then 
      MsgBox   "The   current   model   is   not   an   Physical   Data   model. " 
Else 
      ProcessFolder   mdl 
End   If 

'   This   routine   copy   name   into   comment   for   each   table,   each   column   and   each   view 
'   of   the   current   folder 
Private   sub   ProcessFolder(folder)    
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut then
                     if  trim(tab.comment)="" then'如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.
                        tab.comment   =   tab.name
                     end if  
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns   
                        if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
                           col.comment=   col.name   
                        end if 
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut and trim(view.comment)=""  then    
                  view.comment   =   view.name    
            end   if    
      next    
  
      '   go   into   the   sub-packages    
      Dim   f   '   running   folder    
      For   Each   f   In   folder.Packages    
            if   not   f.IsShortcut   then    
                  ProcessFolder   f    
            end   if    
      Next    
end   sub

2.将Comment内容保存到NAME中,comment2name.vbs 实习互换。语句为:

Option   Explicit    
ValidationMode   =   True    
InteractiveMode   =   im_Batch    
  
Dim   mdl   '   the   current   model    
  
'   get   the   current   active   model    
Set   mdl   =   ActiveModel    
If   (mdl   Is   Nothing)   Then    
      MsgBox   "There   is   no   current   Model "    
ElseIf   Not   mdl.IsKindOf(PdPDM.cls_Model)   Then    
      MsgBox   "The   current   model   is   not   an   Physical   Data   model. "    
Else    
      ProcessFolder   mdl    
End   If    
  
Private   sub   ProcessFolder(folder)    
On Error Resume Next   
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut   then    
                  tab.name   =   tab.comment   
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns    
                  if col.comment="" then   
                  else  
                        col.name=   col.comment    
                  end if  
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut   then    
                  view.name   =   view.comment    
            end   if    
      next    
  
      '   go   into   the   sub-packages    
      Dim   f   '   running   folder    
      For   Each   f   In   folder.Packages    
            if   not   f.IsShortcut   then    
                  ProcessFolder   f    
            end   if    
      Next    
end   sub

3、执行效果

导入成功的SQL脚本

comment转换为name

参看链接:

https://blog.csdn.net/weixin_50750933/article/details/108667494

https://www.cnblogs.com/happy2010/p/10882019.html

如果错过太阳时你流了泪,那你也要错过群星了。
在所有的矛盾中,要优先解决主要矛盾,其他矛盾也就迎刃而解。
不要做个笨蛋,为失去的郁郁寡欢,聪明的人,已经找到了解决问题的办法,或正在寻找。
原文地址:https://www.cnblogs.com/szrs/p/13806988.html