1. 操作步骤
工具:powerdesigner 16.5
快捷键:ctrl+shift+x
执行:点击“run”
说明1:可复制以下脚本,执行pdm转excel;
说明2:表名长度不可超过31个字符,否则执行会中断;
说明3:以下格式仅用于支持当前需求,如果需要调整样式及导出顺序,可参考目录3、目录4中vbs对excel的操作,修改函数 ExportTable 或 函数 AddSheet
2. Comment向Name同步脚本
转自:PowerDesigner 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 code 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 len(tab.comment) <> 0 then
tab.name = tab.comment
end if
Dim col 'running column
for each col in tab.columns
if len(col.comment) <> 0 then
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
if len(view.comment) <> 0 then
view.name = view.comment
end if
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. Excel导出脚本
'******************************************************************************
'* File: Exported_Excel_page.vbs
'* Purpose: 分目录递归,查找当前PDM下所有表,并导出Excel
'******************************************************************************
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
'-----------------------------------------------------------------------------
' 主函数
'-----------------------------------------------------------------------------
' 获取当前活动模型
Dim mdl ' 当前的模型
Set mdl = ActiveModel
Dim EXCEL,catalog,sheet,catalogNum,rowsNum,linkNum
rowsNum = 1
catalogNum = 1
linkNum = 1
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
Else
SetCatalog
ListObjects(mdl)
End If
'----------------------------------------------------------------------------------------------
' 子过程,用于扫描当前包并从当前包中打印对象的信息,然后对当前包的所有子包再次调用相同的子过程
'----------------------------------------------------------------------------------------------
Private Sub ListObjects(fldr)
output "Scanning " & fldr.code
Dim obj ' 运行对象
For Each obj In fldr.children
' 调用子过程来打印对象上的信息
DescribeObject obj
Next
' 进入子包
Dim f ' 运行文件夹
For Each f In fldr.Packages
'调用子程序扫描子程序包
ListObjects f
Next
End Sub
'-----------------------------------------------------------------------------
' 子过程,用于在输出中打印当前对象的信息
'-----------------------------------------------------------------------------
Private Sub DescribeObject(CurrentObject)
if not CurrentObject.Iskindof(cls_NamedObjec