把下面的脚本放进pd的脚本运行器运行即可
'******************************************************************************
option explicit
dim rowsnum
rowsnum = 0
'-----------------------------------------------------------------------------
' 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(-4167)'添加工作表
excel.workbooks(1).sheets(1).name ="表结构"
set sheet = excel.workbooks(1).sheets("表结构")
excel.workbooks(1).sheets.add
excel.workbooks(1).sheets(1).name ="目录"
set sheetlist = excel.workbooks(1).sheets("目录")
showtablelist model,sheetlist
showproperties model, sheet,sheetlist
excel.workbooks(1).sheets(2).select
excel.visible = true
'设置列宽和自动换行
sheet.columns(1).columnwidth = 20
sheet.columns(2).columnwidth = 20
sheet.columns(3).columnwidth = 20
sheet.columns(4).columnwidth = 40
sheet.columns(5).columnwidth = 10
sheet.columns(6).columnwidth = 10
sheet.columns(1).wraptext =true
sheet.columns(2).wraptext =true
sheet.columns(4).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=0
beginrow = rowsnum+1
dim rowindex
rowindex=3
' for each table
output "begin"
dim tab
for each tab in mdl.tables
showtable tab,sheet,rowindex,sheetlist
rowindex = rowindex +1
next
if mdl.tables.count > 0 then
sheet.range("a" & beginrow + 1 & ":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 + 1
' show properties
output "================================"
sheet.cells(rowsnum, 1) =tab.name
sheet.cells(rowsnum, 1).horizontalalignment=3
sheet.cells(rowsnum, 2) = tab.code
'sheet.cells(rowsnum, 5).horizontalalignment=3
'sheet.cells(rowsnum, 6) = ""
'sheet.cells(rowsnum, 7) = "表说明"
sheet.cells(rowsnum, 3) = tab.comment
'sheet.cells(rowsnum, 8).horizontalalignment=3
sheet.range(sheet.cells(rowsnum, 3),sheet.cells(rowsnum, 7)).merge
'设置超链接,从目录点击表名去查看表结构
'字段中文名 字段英文名 字段类型 注释 是否主键 是否非空 默认值
sheetlist.hyperlinks.add sheetlist.cells(rowindex,2), "","表结构"&"!b"&rowsnum
rowsnum = rowsnum + 1
sheet.cells(rowsnum, 1) = "字段中文名"
sheet.cells(rowsnum, 2) = "字段英文名"
sheet.cells(rowsnum, 3) = "字段类型"
sheet.cells(rowsnum, 4) = "注释"
sheet.cells(rowsnum, 5) = "是否主键"
sheet.cells(rowsnum, 6) = "是否非空"
sheet.cells(rowsnum, 7) = "默认值"
'设置边框
sheet.range(sheet.cells(rowsnum-1, 1),sheet.cells(rowsnum, 7)).borders.linestyle = "1"
'sheet.range(sheet.cells(rowsnum-1, 4),sheet.cells(rowsnum, 9)).borders.linestyle = "1"
'字体为10号
sheet.range(sheet.cells(rowsnum-1, 1),sheet.cells(rowsnum, 7)).font.size=10
dim col ' running column
dim colsnum
colsnum = 0
for each col in tab.columns
rowsnum = rowsnum + 1
colsnum = colsnum + 1
sheet.cells(rowsnum, 1) = col.name
'sheet.cells(rowsnum, 3) = ""
'sheet.cells(rowsnum, 4) = col.name
sheet.cells(rowsnum, 2) = col.code
sheet.cells(rowsnum, 3) = col.datatype
sheet.cells(rowsnum, 4) = col.comment
if col.primary = true then
sheet.cells(rowsnum, 5) = "y"
else
sheet.cells(rowsnum, 5) = " "
end if
if col.mandatory = true then
sheet.cells(rowsnum, 6) = "y"
else
sheet.cells(rowsnum, 6) = " "
end if
sheet.cells(rowsnum, 7) = col.defaultvalue
next
sheet.range(sheet.cells(rowsnum-colsnum+1,1),sheet.cells(rowsnum,7)).borders.linestyle = "3"
'sheet.range(sheet.cells(rowsnum-colsnum+1,4),sheet.cells(rowsnum,9)).borders.linestyle = "3"
sheet.range(sheet.cells(rowsnum-colsnum+1,1),sheet.cells(rowsnum,7)).font.size = 10
rowsnum = rowsnum + 2
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=1
' for each table
output "begin"
sheetlist.cells(rowsno, 1) = "主题"
sheetlist.cells(rowsno, 2) = "表中文名"
sheetlist.cells(rowsno, 3) = "表英文名"
sheetlist.cells(rowsno, 4) = "表说明"
rowsno = rowsno + 1
sheetlist.cells(rowsno, 1) = mdl.name
dim tab
for each tab in mdl.tables
if isobject(tab) then
rowsno = rowsno + 1
sheetlist.cells(rowsno, 1) = ""
sheetlist.cells(rowsno, 2) = tab.name
sheetlist.cells(rowsno, 3) = tab.code
sheetlist.cells(rowsno, 4) = tab.comment
end if
next
sheetlist.columns(1).columnwidth = 20
sheetlist.columns(2).columnwidth = 20
sheetlist.columns(3).columnwidth = 30
sheetlist.columns(4).columnwidth = 60
output "end"
end sub
以上就是powerdesigner 的 pdm文件转excel的方法的详细内容。
