详细解释:Excel批量导入PowerDesigner

Excel批量导入PowerDesigner

1. 排版标准excel文件

154723_vk3Z_2333674.pngC:\Users\super_pcf\Desktop\原始参考资料\Excel批量导入PD\Excel批量导入PD规范.xls

2. 打开pd脚本编辑器

PD菜单栏中,依次点击“Tools ->Excute Commands->Edit/Run Script..”打开   批量导.vbs

或者复制代码

154830_C13s_2333674.png 



代码如下:

Option Explicit '强制显示声明模块中的所有变量

'如模块中使用Option Explicit则须用 Dim、Private、Public、ReDim 或 Static 语句来显 式声明所有的变量。

Dim mdl ' the current model变量

Set mdl = ActiveModel

If (mdl Is Nothing) Then

MsgBox "There is no Active Model" '弹出窗口信息

End If

Dim HaveExcel'定义变量

Dim RQ '定义变量

RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")

If RQ = vbYes Then

HaveExcel = True ' Open & Create Excel Document

Dim x1 '定义变量

Set x1 = CreateObject("Excel.Application")

x1.Workbooks.Open "C:\Users\super_pcf\Desktop\原始参考资料\tb_EmployeePraiseCriticism.xls" '指定Excel表的路径"(一定改)

 x1.Workbooks(1).Worksheets("Sheet1").Activate '指定要打开的第一个sheet名称(可能改)

  Else

HaveExcel = False

End If

a x1, mdl

sub a(x1, mdl)

dim rwIndex '定义变量

dim tableName '定义变量

dim colname '定义变量

dim table '定义变量

dim col '定义变量

dim count '定义变量

Dim i

'on error Resume Next

For i= 1 to 2 '指定要导入的sheet的个数(可能改)

For rwIndex = 1 To 14 step 1 '指定要遍次数(可能改)

With x1.Workbooks(1).Worksheets(i) '定义需要写入表结构所在的sheet

'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表"

If .Cells(rwIndex, 1).Value = "" Then

Exit For

End If

If .Cells(rwIndex, 3).Value = "" Then

set table = mdl.Tables.CreateNew '创建一个实体表

table.Name = .Cells(rwIndex , 2).Value

table.Code = .Cells(rwIndex , 1).Value

'table.DefaultValue = .cells(rwIndex,6).value

count = count + 1

Else if.Cells(rwIndex, 2).Value ="" Then

colName = .Cells(rwIndex, 1).Value

Else

 colName = .Cells(rwIndex, 2).Value

End if


set col = table.Columns.CreateNew '创建一列/字段

'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"

if.Cells(rwIndex, 2).Value ="" Then

 col.Name = .Cells(rwIndex, 1).Value '指定列名

 Else

 col.Name = .Cells(rwIndex, 2).Value '

'MsgBox col.Name, vbOK + vbInformation, "列"

End if


col.Code = .Cells(rwIndex,1).Value '指定列说明

if.Cells(rwIndex, 2).Value ="" Then

col.Comment=col.Code

Else

col.Comment = .Cells(rwIndex, 2).Value '指定字段名

End if


col.DataType = .Cells(rwIndex, 3).Value '指定列数据类型 ' col.DefaultValue = .Cells(rwIndex, 6).Value '指定列数据类型

'设置主键

if.Cells(rwIndex, 4).Value = "Primary Key" Then

col.Primary =true

End If

'设置为空值

If.Cells(rwIndex, 5).Value = "NOT NULL" Then

col.Mandatory =true

End If

End If

End With

Next

Next

MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表"

Exit Sub

End Sub



3.简单对比自己Excel表格修改脚本:

154845_lFXj_2333674.png 

4.点击“Run”即可

成功后一切都有只是当我们点击table图标时并不会显示table的实体,如我们右击相应的tablFind in Dragran时会出现如下提示:

161303_XSjh_2333674.png

这时候只需要在编辑区右键》DragranShow symbol》勾选需要的table实体再“OK”就阔以了161344_5d0T_2333674.png



转载于:https://my.oschina.net/u/2333674/blog/479353

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值