PowerDesigner遍历导出所有表到Excel
1.打开需要导出表结构到Excel的pdm文件
2.点击Tools|Execute Commands|Edit/Run Script菜单或按下快捷键Ctrl + Shift + X打开脚本窗口,输入示例VBScript脚本,修改其中的Excel模板路径及工作薄页签,点Run按钮执行即可
3.VBScript脚本
'******************************************************************************
'* File: pdm2excel.vbs
'* Purpose: 分目录递归,查找当前PDM下所有表,并导出Excel
'* Title:
'* Category:
'* Version: 1.0
'******************************************************************************
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
' get the current active model
Dim mdl ' the current model
Set mdl = ActiveModel
Dim EXCEL,sheet,rowsNum
rowsNum = 1If (mdl Is Nothing) ThenMsgBox "There is no Active Model"
ElseSetExcelListObjects(mdl)
End If
'-----------------------------------------------------------------------------
' Sub procedure to scan current package and print information on objects from current package
' and call again the same sub procedure on all children pacakge
' of the current package
'-----------------------------------------------------------------------------
Private Sub ListObjects(fldr)output "Scanning " & fldr.codeDim obj ' running objectFor Each obj In fldr.children' Calling sub procedure to print out information on the objectDescribeObject obj,fldr.nameNext' go into the sub-packagesDim f ' running folderFor Each f In fldr.Packages'calling sub procedure to scan children packageListObjects fNext
End Sub
'-----------------------------------------------------------------------------
' Sub procedure to print information on current object in output
'-----------------------------------------------------------------------------
Private Sub DescribeObject(CurrentObject,packageName)if not CurrentObject.Iskindof(cls_NamedObject) then exit subif CurrentObject.Iskindof(cls_Table) then ExportTable CurrentObject, sheet,packageNameelseoutput "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate) End if
End SubSub SetExcel()Set EXCEL= CreateObject("Excel.Application")' Make Excel visible through the Application object.EXCEL.Visible = TrueEXCEL.workbooks.add(-4167)'添加工作表EXCEL.workbooks(1).sheets(1).name ="PDM导出到Excel"set sheet = EXCEL.workbooks(1).sheets("PDM导出到Excel")' Place some text in the first Row of the sheet.sheet.Cells(rowsNum, 1).Value = "序号"sheet.Cells(rowsNum, 2).Value = "表名"sheet.Cells(rowsNum, 3).Value = "表中文名"sheet.Cells(rowsNum, 4).Value = "表注释"sheet.Cells(rowsNum, 5).Value = "字段名"sheet.Cells(rowsNum, 6).Value = "字段中文名"sheet.Cells(rowsNum, 7).Value = "字段注释"sheet.Cells(rowsNum, 8).Value = "是否主键"sheet.Cells(rowsNum, 9).Value = "是否非空"sheet.Cells(rowsNum, 10).Value = "字段类型"sheet.Cells(rowsNum, 11).Value = "表所在package名称"
End SubSub ExportTable(tab, sheet,packageName)Dim col ' running columnDim colsNumcolsNum = 0for each col in tab.columnscolsNum = colsNum + 1rowsNum = rowsNum + 1sheet.Cells(rowsNum, 1).Value = colsNumsheet.Cells(rowsNum, 2).Value = tab.codesheet.Cells(rowsNum, 3).Value = tab.namesheet.Cells(rowsNum, 4).Value = tab.commentsheet.Cells(rowsNum, 5).Value = col.codesheet.Cells(rowsNum, 6).Value = col.namesheet.Cells(rowsNum, 7).Value = col.commentIf col.Primary = true Thensheet.cells(rowsNum, 8) = "是" Elsesheet.cells(rowsNum, 8) = "否" End IfIf col.Mandatory = true Thensheet.cells(rowsNum, 9) = "是" Elsesheet.cells(rowsNum, 9) = "否" End Ifsheet.Cells(rowsNum, 10).Value = col.datatypesheet.Cells(rowsNum, 11).Value =packageNamenext'设置列宽sheet.Columns(1).ColumnWidth =5 sheet.Columns(2).ColumnWidth = 30 sheet.Columns(3).ColumnWidth = 30 sheet.Columns(4).ColumnWidth = 30 sheet.Columns(5).ColumnWidth = 30 sheet.Columns(6).ColumnWidth = 30 sheet.Columns(7).ColumnWidth = 30 sheet.Columns(8).ColumnWidth = 10 sheet.Columns(9).ColumnWidth = 10 sheet.Columns(10).ColumnWidth = 20 sheet.Columns(11).ColumnWidth = 30 '若果需要表头居中显示就把下面的注释内容放开'sheet.Range(sheet.cells(1,1),sheet.cells(1,11)).HorizontalAlignment = 3sheet.Range(sheet.cells(1,1),sheet.cells(1,11)).Font.Bold = Trueoutput "Exported table: "+ +tab.Code+"("+tab.Name+")"
End Sub
[2024-06-08]