快捷搜索:  汽车  科技

pdm表怎么生成(将.pdm表结构批量导出到excel)

pdm表怎么生成(将.pdm表结构批量导出到excel)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."

你是不是从客户那儿收到了几个xxx.pdm的文件,不要萌,这是 PowerDesigner 文件,里面就是你要看到的数据库表结构。

赶快去下载 PowerDesigner (如果你还没有的话)http://soft.onlinedown.net/soft/577763.htm

下载好,安装!打开pdm文件,File > Open > 选择文件

pdm表怎么生成(将.pdm表结构批量导出到excel)(1)

ctrl shift x,粘贴下面代码,Run

pdm表怎么生成(将.pdm表结构批量导出到excel)(2)

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 BOOK SheetLIST set EXCEL = CREATEOBJECT("Excel.Application") set BOOK = EXCEL.workbooks.add(-4167) ' 创建工作簿 BOOK.sheets(1).name ="目录" 'Sheet名称 set SHEETLIST = BOOK.sheets("目录") 'Sheet对象 Output "[line(21) info]: book.Sheet: " BOOK.Sheets(1).Name BOOK.sheets.add ' 添加工作表Sheet output "[line(24) info]: book.Sheet: " BOOK.Sheets(1).Name 'EXCEL.workbooks(1).sheets(1).name ="表结构" 'Sheet1名称 'set SHEET = EXCEL.workbooks(1).sheets("表结构") 'Sheet1对象 ShowTableList Model SHEETLIST ShowProperties Model BOOK output "[line(32) info]: Select: " BOOK.Sheets(BOOK.Sheets.count).name BOOK.Sheets(BOOK.Sheets.count).Select '选择默认打开的工作表 EXCEL.visible = true ' 弹出Excel工作簿 '不显示网格线 'EXCEL.ActiveWindow.DisplayGridlines = True End If '----------------------------------------------------------------------------- ' Show properties of tables '----------------------------------------------------------------------------- Sub ShowProperties(mdl book) ' Show tables of the current model/package rowsNum=0 beginrow = rowsNum 1 output "[line(46) info]: tables count : " &mdl.tables.count Dim rowIndex ' 为目录Sheet设置链接位置 rowIndex=3 output "[line(50) info]: 表结构 begin ========================" ' For each table Dim tab ' Power Tables For Each tab In mdl.tables ShowTable mdl tab book rowIndex rowIndex = rowIndex 1 Next output "[line(58) info]: 表结构 end !Sheet totals is : " & book.Sheets.count End Sub '----------------------------------------------------------------------------- ' Show table properties '----------------------------------------------------------------------------- Sub ShowTable(mdl tab book rowIndex) If IsObject(tab) Then rowsNum = 0 rowsNum = rowsNum 1 'rowsNum=1 工作表第一行 Dim sheet set sheet = book.Sheets(1) ' Show properties Output "[line(72) info]: " & book.Sheets.count &":" sheet.name ":" tab.name ' 设置列宽 sheet.Columns(1).ColumnWidth = 20 sheet.Columns(2).ColumnWidth = 20 sheet.Columns(3).ColumnWidth = 20 sheet.Columns(4).ColumnWidth = 40 '根据需要添加列数,这里是4列,接着是自动换行 sheet.Columns(1).WrapText =true sheet.Columns(2).WrapText =true sheet.Columns(4).WrapText =true Dim list set list = book.Sheets(book.Sheets.count) output "[line(85) info]:llist:为工作表" list.name "工作表中的单元格设置超链接,对应1个表结构" list.Hyperlinks.Add list.cells(rowIndex 2) "" sheet.name &"!B"&rowsNum '字段名称 字段编码 数据类型 注释 sheet.cells(rowsNum 1) = "字段名称" sheet.cells(rowsNum 2) = "字段编码" sheet.cells(rowsNum 3) = "数据类型" sheet.cells(rowsNum 4) = "注释" '设置边框 sheet.Range(sheet.cells(rowsNum 1) sheet.cells(rowsNum 4)).Borders.LineStyle = "1" '字体为10号 sheet.Range(sheet.cells(rowsNum 1) sheet.cells(rowsNum 4)).Font.Size=10 Dim col ' running column Dim colsNum colsNum = 0 for each col in tab.columns rowsNum = rowsNum 1 colsNum = colsNum 1 sheet.cells(rowsNum 1) = col.name sheet.cells(rowsNum 2) = col.code sheet.cells(rowsNum 3) = col.datatype sheet.cells(rowsNum 4) = col.comment next rowsNum = rowsNum 1 sheet.cells(rowsNum 1) =tab.name sheet.cells(rowsNum 1).HorizontalAlignment=3 sheet.cells(rowsNum 2) = tab.code 'sheet.cells(rowsNum 3) = tab.comment 'sheet.Range(sheet.cells(rowsNum 3) sheet.cells(rowsNum 4)).Merge ' 单元格合并 If book.Sheets.count-1 < mdl.tables.count Then book.Sheets.Add End If End Sub '----------------------------------------------------------------------------- ' Show List Of Table '----------------------------------------------------------------------------- Sub ShowTableList(mdl SheetList) ' Show tables of the current model/package Dim rowsNo rowsNo=1 output "[line(131) info]: 目录程序 begin" SheetList.cells(rowsNo 1) = "主题" SheetList.cells(rowsNo 2) = "表名称" SheetList.cells(rowsNo 3) = "表编码" SheetList.cells(rowsNo 4) = "表说明" rowsNo = rowsNo 1 SheetList.cells(rowsNo 1) = mdl.name ' For each table Dim tab For Each tab In mdl.tables If IsObject(tab) Then rowsNo = rowsNo 1 SheetList.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 = 20 SheetList.Columns(2).ColumnWidth = 20 SheetList.Columns(3).ColumnWidth = 30 SheetList.Columns(4).ColumnWidth = 60 End Sub

pdm表怎么生成(将.pdm表结构批量导出到excel)(3)

pdm表怎么生成(将.pdm表结构批量导出到excel)(4)

如果你想讲所有图标导出到同一张sheet,其实我不建议,如果有需要,那么粘贴下面的代码:

'****************************************************************************** '* File: pdm2excel.txt '* Title: pdm export to excel '* Purpose: To export the tables and columns to Excel '* Model: Physical Data Model 16.5 Microsoft Office 2007 '* Objects: Table Column View '****************************************************************************** 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 set EXCEL = CREATEOBJECT("Excel.Application") EXCEL.workbooks.add(-4167)'添加工作表 EXCEL.workbooks(1).sheets(1).name ="test" set sheet = EXCEL.workbooks(1).sheets("test") ShowProperties Model SHEET EXCEL.visible = true '设置列宽和自动换行 sheet.Columns(1).ColumnWidth = 20 sheet.Columns(2).ColumnWidth = 40 sheet.Columns(4).ColumnWidth = 20 sheet.Columns(5).ColumnWidth = 20 sheet.Columns(6).ColumnWidth = 15 sheet.Columns(1).WrapText =true sheet.Columns(2).WrapText =true sheet.Columns(4).WrapText =true End If '----------------------------------------------------------------------------- ' Show properties of tables '----------------------------------------------------------------------------- Sub ShowProperties(mdl sheet) ' Show tables of the current model/package rowsNum=0 beginrow = rowsNum 1 ' For each table output "begin" Dim tab For Each tab In mdl.tables ShowTable tab sheet Next if mdl.tables.count > 0 then sheet.Range("A" & beginrow 1 & ":A" & rowsNum).Rows.Group end if output "end" End Sub '----------------------------------------------------------------------------- ' Show table properties '----------------------------------------------------------------------------- Sub ShowTable(tab sheet) If IsObject(tab) Then Dim rangFlag rowsNum = rowsNum 1 ' Show properties Output "================================" sheet.cells(rowsNum 1) = "实体名" sheet.cells(rowsNum 2) =tab.name sheet.cells(rowsNum 3) = "" sheet.cells(rowsNum 4) = "表名" sheet.cells(rowsNum 5) = tab.code sheet.Range(sheet.cells(rowsNum 5) sheet.cells(rowsNum 6)).Merge rowsNum = rowsNum 1 sheet.cells(rowsNum 1) = "属性名" sheet.cells(rowsNum 2) = "说明" sheet.cells(rowsNum 3) = "" sheet.cells(rowsNum 4) = "字段中文名" sheet.cells(rowsNum 5) = "字段名" sheet.cells(rowsNum 6) = "字段类型" '设置边框 sheet.Range(sheet.cells(rowsNum-1 1) sheet.cells(rowsNum 2)).Borders.LineStyle = "1" sheet.Range(sheet.cells(rowsNum-1 4) sheet.cells(rowsNum 6)).Borders.LineStyle = "1" Dim col ' running column Dim colsNum colsNum = 0 for each col in tab.columns rowsNum = rowsNum 1 colsNum = colsNum 1 sheet.cells(rowsNum 1) = col.name sheet.cells(rowsNum 2) = col.comment sheet.cells(rowsNum 3) = "" sheet.cells(rowsNum 4) = col.name sheet.cells(rowsNum 5) = col.code sheet.cells(rowsNum 6) = col.datatype next sheet.Range(sheet.cells(rowsNum-colsNum 1 1) sheet.cells(rowsNum 2)).Borders.LineStyle = "2" sheet.Range(sheet.cells(rowsNum-colsNum 1 4) sheet.cells(rowsNum 6)).Borders.LineStyle = "2" rowsNum = rowsNum 1 Output "FullDescription: " tab.Name End If End Sub

此处无导出截图,有感兴趣的小伙伴欢迎评论区截图~~~

猜您喜欢: