一、前言
在使用powerdesigner中,需要将建立的表可以导出到word。就是本文的由来,本文不是什么教程,高手也可直接飘过,仅仅作为一篇学习笔记,发布出来。
在上一篇PowerDesigner 学习系列 简单操作 介绍了pd的简单操作,这篇将描述如何从powerdesigner中导出表到word中。本文的powerdesigner使用的版本为12.5。
本文同步发表于 伊牛娃
二、模版修改
在导出表时,powerdesigner默认为我们提供了很多的模版,在工具栏中选择【Report--->Report Template】即可看到所有的默认模版。如图一:

图一 模版列表
这里我们为了导出powerdesigner中创建的表,在工具栏中选择【Report--->Reports】(快捷键Ctrl+E),然后创建一个New Report
,如下图二所以,选择Standard Physical Report,这里选择的标准的模版,点击OK确定。

图二 创建新的Report
从工具栏【Report--->Print Preview】或者点击图标
同样可以预览导出到word的效果了。效果如图三所示:

图三 导出到word中预览效果
从【图三】中的工具栏里面HTM和RTF两种导出格式。如果导出到word选择RTF格式即可,但是我们从【图三】中看出红色标出的部分,1 是word的页眉,同样还有页脚信息 ,2 是一些列的属性清单。

图四 设置页眉、页脚
在【图四】中,选择Header/Footer后,删掉Header里面的%MODULE%%MODELNAME%,删掉Footer里面的%APPNAME%%DATE%页数 %PAGE%,User_defined footer就会自动勾上,这样就去掉了页眉、页脚了
还有其他的比如表前面的自增序号,第一页中的创建者、版本、日期信息也不需要,我们可以进行配置去掉,如下【图五】




图五 Properties配置
在图五中,在默认配置中(General)勾上No paragraph numbering即可取消表前面的自增序号,在Title Page中选择 No Title Page就不会生成第一页中关于创建者、版本、日期等信息。
在【图三】中,预览看到的内容太多,就必须删除一些我们不需要的内容,经过删减之后,如下【图六】所示

图六
在【图六】中右键单击【List of Table Columns - 表<%PARENT%>列说明】,从菜单中选择 Edit Title...,就可以编辑成现在我们已看到的。然后,在右键菜单中选择Layout...,选择我们所需要显示的内容,Code表示列名称,一般用英 文单词或拼音字母表示,Name一般用中文描述,Data Type 表示数据类型,Comment表示字段备注或字段说明等。
到此基本上已经完成了powerdesigner模版的修改
三、导出表
然后点击[Report---->Generate RTF]导出到word中,最后我们看看导出到word的效果,如下图:

图七 导出到word效果
四、保存模版
通过上文,我们完成了自己所需的模版,然后就保存,以后可以直接使用即可,在工具栏中[Report--->Create Template From Section],然后Ctrl+S就会要求保存,取名保存即可。
五、模版下载
点击下载
六、文笔有限,尽量做到图文并茂,若有不妥之处,欢迎大家使劲拍砖
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 comment 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
tab.comment = tab.name
Dim col ' running column
for each col in tab.columns
col.comment= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
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
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
Private sub ProcessFolder(folder)
OnErrorResumeNext
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.name = tab.comment
Dim col ' running column
for each col in tab.columns
if col.comment=""then
else
col.name= col.comment
endif
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name = view.comment
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
以上两段代码都是VB脚本,在PowerDesigner中使用方法为:
PowerDesigner->Tools->Execute Commands->Edit/Run Scripts
将代码Copy进去执行就可以了,是对整个CDM或PDM进行操作
1. 修改name不随着code的值变动
方法:PowerDesign中的选项菜单里修改,在Tool-->Options->Dialog->modes->to Code mirroring,这里默认是让名称和代码同步,将前面的复选框去掉就行了。
2. 设置sql语句中表名与字段名默认大小写
方法:进入Tools-Model Options-Naming Convention,把Name和Code的标签的Charcter case选项设置成Uppercase或者Lowercase
3. 去掉sql语句中表名与字段名前的引号
方 法:进入Database->Edit current database->Script->Sql->Format,有一项CaseSensitivityUsingQuote,它的 comment为“Determines if the case sensitivity for identifiers is managed using double quotes”,表示是否适用双引号来规定标识符的大小写, 可以看到右边的values默认值为“YES”,改为“No”即可!
4. 给字段设置默认值
方法:在table properties上的customize columns and filter上选择default value,显示的默认值为灰色不能修改,在某一列的默认值上选择properties,在standard checks中填写default的值即可
5. 在Name后面加中文的注释 #开始
方法:进入Tools-Model Options-Naming Convention,选中Name To Code选项卡下输入Script 1中代码,并选中允许名称/代码惯例
.set_value(_First,true,new)
.foreach_part(%Name%,"'#'")
.if(%_First%)
.delete(%CurrentPart%)
.set_value(_First,false, update)
.else
%CurrentPart%
.endif
.next