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.5\Resource Files\Report 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM