1.将Powerdesigner中的表(PDM)导入到execel中

  Ctrl+Shift+X/tool->Execute commands ->Edit/Run script

  粘贴如下vbscript脚本(经测试成功运行):

'******************************************************************************
Option Explicit
Dim rowsNum
rowsNum =
'-----------------------------------------------------------------------------
' 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, SHEETLIST
set EXCEL = CREATEOBJECT("Excel.Application")
EXCEL.workbooks.add(-)'添加工作表
EXCEL.workbooks().sheets().name ="表结构"
set SHEET = EXCEL.workbooks().sheets("表结构") EXCEL.workbooks().sheets.add
EXCEL.workbooks().sheets().name ="目录"
set SHEETLIST = EXCEL.workbooks().sheets("目录")
ShowTableList Model,SHEETLIST ShowProperties Model, SHEET,SHEETLIST EXCEL.workbooks().Sheets().Select
EXCEL.visible = true
'设置列宽和自动换行
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().WrapText =true
sheet.Columns().WrapText =true
sheet.Columns().WrapText =true
'不显示网格线
EXCEL.ActiveWindow.DisplayGridlines = False End If
'-----------------------------------------------------------------------------
' Show properties of tables
'-----------------------------------------------------------------------------
Sub ShowProperties(mdl, sheet,SheetList)
' Show tables of the current model/package
rowsNum=
beginrow = rowsNum+
Dim rowIndex
rowIndex=
' For each table
output "begin"
Dim tab
For Each tab In mdl.tables
ShowTable tab,sheet,rowIndex,sheetList
rowIndex = rowIndex +
Next
if mdl.tables.count > then
sheet.Range("A" & beginrow + & ":A" & rowsNum).Rows.Group
end if
output "end"
End Sub
'-----------------------------------------------------------------------------
' Show table properties
'-----------------------------------------------------------------------------
Sub ShowTable(tab, sheet,rowIndex,sheetList)
If IsObject(tab) Then
Dim rangFlag
rowsNum = rowsNum +
' Show properties
Output "================================"
sheet.cells(rowsNum, ) =tab.name
sheet.cells(rowsNum, ).HorizontalAlignment=
sheet.cells(rowsNum, ) = tab.code
'sheet.cells(rowsNum, 5).HorizontalAlignment=3
'sheet.cells(rowsNum, 6) = ""
'sheet.cells(rowsNum, 7) = "表说明"
sheet.cells(rowsNum, ) = tab.comment
'sheet.cells(rowsNum, 8).HorizontalAlignment=3
sheet.Range(sheet.cells(rowsNum, ),sheet.cells(rowsNum, )).Merge
'设置超链接,从目录点击表名去查看表结构
'字段中文名 字段英文名 字段类型 注释 是否主键 是否非空 默认值
sheetList.Hyperlinks.Add sheetList.cells(rowIndex,), "","表结构"&"!B"&rowsNum
rowsNum = rowsNum +
sheet.cells(rowsNum, ) = "字段中文名"
sheet.cells(rowsNum, ) = "字段英文名"
sheet.cells(rowsNum, ) = "字段类型"
sheet.cells(rowsNum, ) = "字段长度"
sheet.cells(rowsNum, ) = "注释"
sheet.cells(rowsNum, ) = "是否主键"
sheet.cells(rowsNum, ) = "是否外键"
sheet.cells(rowsNum, ) = "是否非空"
sheet.cells(rowsNum, ) = "默认值"
'设置边框
sheet.Range(sheet.cells(rowsNum-, ),sheet.cells(rowsNum, )).Borders.LineStyle = ""
'字体为10号
sheet.Range(sheet.cells(rowsNum-, ),sheet.cells(rowsNum, )).Font.Size=
Dim col ' running column
Dim colsNum
colsNum =
for each col in tab.columns
rowsNum = rowsNum +
colsNum = colsNum +
sheet.cells(rowsNum, ) = col.name
sheet.cells(rowsNum, ) = col.code
sheet.cells(rowsNum, ) = col.datatype
sheet.cells(rowsNum, ) = col.length
'sheet.cells(rowsNum, 4) = col.name
sheet.cells(rowsNum, ) = col.comment
If col.Primary = true Then
sheet.cells(rowsNum, ) = "Y"
Else
sheet.cells(rowsNum, ) = " "
End If
If col.ForeignKey= true Then
sheet.cells(rowsNum, ) = "Y"
Else
sheet.cells(rowsNum, ) = " "
End If
If col.Mandatory = true Then
sheet.cells(rowsNum, ) = "Y"
Else
sheet.cells(rowsNum, ) = " "
End If
sheet.cells(rowsNum, ) = col.defaultvalue
next
sheet.Range(sheet.cells(rowsNum-colsNum+,),sheet.cells(rowsNum,)).Borders.LineStyle = ""
sheet.Range(sheet.cells(rowsNum-colsNum+,),sheet.cells(rowsNum,)).Font.Size =
rowsNum = rowsNum + Output "FullDescription: " + tab.Name
End If End Sub
'-----------------------------------------------------------------------------
' Show List Of Table
'-----------------------------------------------------------------------------
Sub ShowTableList(mdl, SheetList)
' Show tables of the current model/package
Dim rowsNo
rowsNo=
' For each table
output "begin"
SheetList.cells(rowsNo, ) = "主题"
SheetList.cells(rowsNo, ) = "表中文名"
SheetList.cells(rowsNo, ) = "表英文名"
SheetList.cells(rowsNo, ) = "表说明"
rowsNo = rowsNo +
SheetList.cells(rowsNo, ) = mdl.name
Dim tab
For Each tab In mdl.tables
If IsObject(tab) Then
rowsNo = rowsNo +
SheetList.cells(rowsNo, ) = ""
SheetList.cells(rowsNo, ) = tab.name
SheetList.cells(rowsNo, ) = tab.code
SheetList.cells(rowsNo, ) = tab.comment
End If
Next
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
output "end"
End Sub

2.Excel导入Powerdesigner生成模型的vbscript脚本:

'******************************************************************************
'开始
Option Explicit
Dim tab_name,tab_code,tab_comment
Dim b_r, e_r, s_r, j, m, n
Dim mdl ' the current model
dim count
Dim HaveExcel
Dim RQ
Dim file_name,WScript
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
End If
RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")
If RQ = vbYes Then
HaveExcel = True
' Open & Create Excel Document
Else
HaveExcel = False
End If
file_name = selectFile()
if file_name <> "" then
Dim x1 '
Set x1 = CreateObject("Excel.Application")
x1.Workbooks.Open file_name '指定excel文档路径
x1.Workbooks().Worksheets("表结构").Activate '指定要打开的sheet名称
j =
do while n <
if x1.Workbooks().Worksheets("表结构").cells(j,).value <> "" then
call a(x1, mdl, j, getRow(x1, j))
'msgbox j & "--" & getRow(x1, j)
count = count +
j = getRow(x1, j)
n =
end if
j = j +
n = n +
loop
'MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表 导入完毕!"
MsgBox "生成数据表结构共计 " & CStr(count) & " 表导入完毕!"
x1.Workbooks().close
x1.quit
else
msgbox "没有选择文件!"
end if sub a(x1, mdl, r_0,r_9)
dim rwIndex
dim tableName
dim colname
dim table
dim col tab_name = ucase(x1.Workbooks().Worksheets("表结构").cells(r_0,).value) '指定表名,如果在Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
tab_code = ucase(x1.Workbooks().Worksheets("表结构").cells(r_0,).value) '指定表名
tab_comment = ucase(x1.Workbooks().Worksheets("表结构").cells(r_0,).value) on error Resume Next
set table = mdl.Tables.CreateNew '创建一个表实体
table.Name = tab_name
table.Code = tab_code
table.Comment = tab_comment For rwIndex = r_0 + To r_9 '指定要遍历的Excel行标 由于第1行是表头,从第2行开始
With x1.Workbooks().Worksheets("表结构")
If .Cells(rwIndex, ).Value = "" Then
Exit For
End If
set col = table.Columns.CreateNew '创建一列/字段
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
If .Cells(rwIndex, ).Value = "" Then
col.Name = ucase(.Cells(rwIndex, ).Value) '指定列名
Else
col.Name = ucase(.Cells(rwIndex, ).Value)
End If
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Code = ucase(.Cells(rwIndex, ).Value) '指定列名 col.DataType = ucase(.Cells(rwIndex, ).Value) '指定列数据类型 col.Comment = ucase(.Cells(rwIndex, ).Value) '指定列说明 If ucase(.Cells(rwIndex, ).Value) = "Y" Then
col.Primary = true '指定主键
col.defaultvalue = ucase(.Cells(rwIndex,).value)
End If
If ucase(.Cells(rwIndex,).value) = "Y" then
col.defaultvalue = ucase(.Cells(rwIndex,).value)
col.Mandatory = true
End If End With
Next
End sub Function getRow(x1, s_r)
dim i, k
k = s_r
do while x1.Workbooks().Worksheets("表结构").cells(k,).value <> ""
k = k +
if x1.Workbooks().Worksheets("表结构").cells(k,).value = "" then
getRow = k -
exit function
end if
loop
End Function
Function SelectFile()
Dim shell : Set shell = CreateObject("WScript.Shell")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim tempFolder : Set tempFolder = fso.GetSpecialFolder()
Dim tempName : tempName = fso.GetTempName()
Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")
tempFile.Write _
"<html>" & _
"<head>" & _
"<title>Browse</title>" & _
"</head>" & _
"<body>" & _
"<input type='file' id='f' />" & _
"<script type='text/javascript'>" & _
"var f = document.getElementById('f');" & _
"f.click();" & _
"var shell = new ActiveXObject('WScript.Shell');" & _
"shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\MsgResp', f.value);" & _
"window.close();" & _
"</script>" & _
"</body>" & _
"</html>"
tempFile.Close
shell.Run tempFolder & "\" & tempName & ".hta", , True
SelectFile = shell.RegRead("HKEY_CURRENT_USER\Volatile Environment\MsgResp")
shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"
End Function

3.使用方式:

  以上两个脚本分别以后缀名称为“.vbs”的方式保存;

4.参考网址:http://www.w 2bc.com/article/225953

Powerdesigner+Execel的更多相关文章

  1. 真正的汉化-PowerDesigner 16.5 汉化

    一.背景 经常使用PowerDesigner,之前使用15版本,后来16出来后,就一直在使用16,不过一直是英文.一些同事对使用英文版总显示有些吃力. 遍寻百度.必应,都没有找到真正的针对版本16的汉 ...

  2. 用VB脚本批到导入字段到PowerDesigner

    在PowerDesigner使用脚本批量导入excel中记录的表结构信息,由于需要通过powerdesigner逆向工程创建一些sybase IQ的表,由于是接口数据,只有excel表,手动导入太耗时 ...

  3. PowerDesigner(数据建模)使用大全

    什么是PowerDesigner 引入百度百科的说法是: power designer是能进行数据库设计的强大的软件,是一款开发人员常用的数据库建模工具.使用它可以分别从概念数据模型(Conceptu ...

  4. PowerDesigner从Sqlserver中反转为带注释的字典及快捷键操作

    PowerDesigner的操作经常忘记,所以把常用的功能记录下来备忘. 1.修改反转过来的字段 PowerDesigner从数据库反转的时候,默认不带注释,需要先进行修改. 输入如下脚本: {OWN ...

  5. PowerDesigner 常用设置

    1.使用 JDBC 方式连接 Oracle 逆向生成数据库 PDM 使用 ODBC 方式连接 Oracle 数据库可以借鉴这位兄弟的博客:http://www.cnblogs.com/clivehua ...

  6. powerdesigner显示列描述信息

    将Comment中的字符COPY至Name中 -------------------------------------------------- Option   Explicit Validati ...

  7. PowerDesigner从SqlServer数据库中导入实体模型

    PowerDesigner从SqlServer数据库中导入实体模型 时间 2013-06-28 10:26:34 CSDN博客 原文  http://blog.csdn.net/sxycxwb/art ...

  8. PowerDesigner连接Oracle并导出表结构

    环境:Oracle 11G(远程) + win32_11gR2_client + PowerDesigner 15 一.下载.安装.配置 1.下载地址 win32_11gR2_client客户端下载地 ...

  9. PowerDesigner通过SQL语句生成PDM文件

    前提: 我用的是PowerDesigner15 数据库为Mysql5.5 步骤如下: 第一步:File->New Model 点击OK创建模板就行了 备注:在创建物理模型时DBMS下拉框是空的, ...

随机推荐

  1. HashMap与ConcurrentHashMap

    从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是线程安全的,因此多线程操作时需要格外小心. 在JDK1.5中,伟大的Doug Lea给我们带来了concurrent包,从 ...

  2. 基于2-channel network的图片相似度判别

    一.相关理论 本篇博文主要讲解2015年CVPR的一篇关于图像相似度计算的文章:<Learning to Compare Image Patches via Convolutional Neur ...

  3. springMVC(7)---表单标签

    springMVC(7)---表单标签 form标签作用                                     简单来讲form表单有两大作用 1:第一就是往后端提交数据或者前端回显 ...

  4. python基础(八)生成器,迭代器,装饰器,递归

    生成器 在函数中使用yield关键字就会将一个普通的函数变成一个生成器(generator),普通的函数只能使用return来退出函数,而不执行return之后的代码.而生成器可以使用调用一个next ...

  5. Android CoordinatorLayout、AppBarLayout、DrawerLayout、NavigationView 的使用及问题小结

    这里只对Material Design中这几种组件使用的重要部分以及容易出现问题的地方进行汇总(遇坑请直接看最后常见问题部分),详细用法请自行查阅官方文档 一.CoordinatorLayout 介绍 ...

  6. Java中的移动和复制

    public static boolean Move(File srcFile, String destPath) { // Destination directory File dir = new ...

  7. 【Splay】bzoj1500(听说此题多码上几遍就能不惧任何平衡树题)

    1500: [NOI2005]维修数列 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 15112  Solved: 4996[Submit][Statu ...

  8. Java与算法之(10) - 希尔排序

    希尔排序是插入排序的一种,是直接插入排序的改进版本. 对于上节介绍的直接插入排序法,如果数据原来就已经按要求的顺序排列,则在排序过程中不需要进行数据移动操作,即可得到有序数列.但是,如果最初的数据是按 ...

  9. JavaScript中数组map()方法

    JavaScript 数组map()方法创建一个新的数组使用调用此数组中的每个元素上所提供的函数的结果.语法 ? 1 array.map(callback[, thisObject]); 下面是参数的 ...

  10. Android应用程序使用两个LinearLayout编排5个Button控件

    学习存档: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...