1、将数据字典中的数据表结构粘贴到Excel文件中,整理成如下图所示格式
2、在powerdesigner中创建PDM工程,选中该工程,然后打开脚本代码窗口:Tools-ExecuteCommands - Edit\RunScript ,编写代码脚本。
脚本
'
Dim mdl ' thecurrent model
Set mdl =ActiveModel
If (mdl IsNothing) Then
MsgBox "没有活动的模版"
End If
Dim HaveExcel
Dim RQ
RQ = vbYes'MsgBox("Is Excel Installed on your machine ?", vbYesNo +vbInformation, "Confirmation")
If RQ = vbYesThen
HaveExcel = True
' Open &Create Excel Document
Dim x1 '
Set x1 =CreateObject("Excel.Application")
x1.Workbooks.Open"C:\Users\axyx\Desktop\aaaaaaa.xls" '指定excel文档路径
Else
HaveExcel =False
End If
a x1, mdl
sub a(x1, mdl)
dim rwIndex
dim tableName
dim colname
dim table
dim col
dim count
on error ResumeNext
set table =mdl.Tables.CreateNew '创建一个表实体
table.Name ="学号" '指定表名,如果在Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
table.Code ="stu_center" '指定表名编码
count = count +1
For rwIndex = 2To 1000 '指定要遍历的Excel行标,此处第一列为列名,古从第二行开始循环
Withx1.Workbooks(1).Worksheets("sheet1")'需要循环的sheet名称
If.Cells(rwIndex, 1).Value = "" Then
Exit For
End If
set col =table.Columns.CreateNew '创建一列/字段
col.Name =.Cells(rwIndex, 1).Value '指定列名
col.Code =.Cells(rwIndex, 2).Value '指定列名编码
col.DataType =.Cells(rwIndex, 3).Value '指定列数据类型
col.Length =.Cells(rwIndex, 4).Value '指定字段长度
col.Precision =.Cells(rwIndex, 5).Value '指定字段长度
'指定主键
If.Cells(rwIndex, 6).Value = "是" Then
col.Primary =true
End If
'指定列是否可空 true 为不可空
If.Cells(rwIndex, 7).Value = "否" Then
col.Mandatory =true
End If
col.Comment =.Cells(rwIndex, 8).Value '指定列说明
End With
Next
MsgBox "生成数据表结构共计 " + CStr(count), vbOK+ vbInformation, "表"
Exit Sub
Endsub