數據庫表結構轉成設計書,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)
配置完畢 後 點擊確定
4,選擇剛剛配置的數據源,輸入相應的用戶名和密碼 即可。
=====得到PDM物理設計說明書
選中tables
ctrl + shift +x 然後運行腳本
1 ‘****************************************************************************** 2 Option Explicit 3 Dim rowsNum 4 rowsNum = 0 5 ‘-----------------------------------------------------------------------------View Code6 ‘ 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
該代碼為宏代碼
參考:
https://blog.csdn.net/a824444865/article/details/50072655
https://www.cnblogs.com/gaocong/p/6553080.html
數據庫表結構轉成設計書,PowerDesigner 表格導出為excel