打开powerdesign
新建 conceptual data model (CDM)
此脚本只试用于 CDM图
打开菜单栏 Tool -> execute command ->Edit/Run Script
脚本如下:
On Error Resume Next
dim excelPathexcelPath="c:/a.xls"
dim sheetCount
Dim model ' the current model
Set model = ActiveModel
If (model Is Nothing) Then
MsgBox "There is no Active Model"
End If
Dim RQ
RQ=MsgBox ("是否安装excel?",vbYesNo + vbInformation,"Confirmation")
if RQ = vbyes then
Set x=createobject("Excel.Application")
x.workbooks.open excelPath
x.workbooks(1).worksheets(1).activate
sheetCount=x.workbooks(1).worksheets.count
'开始处理多个sheet
for each tmpSheet in x.workbooks(1).worksheets
if tmpSheet.cells(1,1)<>"" then
'获取到总行数
dim rowCount
rowCount=tmpSheet.usedrange.rows.count
'获取到总列树
dim colCount
colCount=tmpSheet.usedrange.columns.count
'首先获取表名称 第一列是表名称
tableName=tmpSheet.cells(1,1).value
set newEntity=Activemodel.entities.createnew
newEntity.name=tableName
newEntity.code=tableName
for rowIndex=2 to rowCount
set newColumn=newEntity.attributes.createnew
'msgbox rowIndex
'msgbox tmpSheet.cells(rowIndex,1)
if tmpSheet.cells(rowIndex,1) <>"" then
newColumn.name=tmpSheet.cells(rowIndex,1)
newColumn.code=tmpSheet.cells(rowIndex,1)
newColumn.datatype="Variable characters (60)"
end if
next
end if
next
msgbox "生成完成"
x.workbooks.close()
x.quit
end if
If Err.Number <> 0 Then
x.workbooks.close()
x.quit
end if
excel 格式:
![](http://hi.csdn.net/attachment/201202/10/0_132886086831w4.gif)