詳細解釋:Excel批量導入PowerDesigner

Excel批量導入PowerDesigner

1. 排版標準excel文件編輯器

C:\Users\super_pcf\Desktop\原始參考資料\Excel批量導入PD\Excel批量導入PD規範.xlsspa

2. 打開pd腳本編輯器excel

PD菜單欄中,依次點擊「Tools ->Excute Commands->Edit/Run Script..」打開   批量導.vbsorm

或者複製代碼ip

 



代碼以下:md5

Option Explicit '強制顯示聲明模塊中的全部變量ci

'如模塊中使用Option Explicit則須用 Dim、Private、Public、ReDim 或 Static 語句來顯 式聲明全部的變量。get

Dim mdl ' the current model變量it

Set mdl = ActiveModelio

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表格修改腳本:

 

4.點擊「Run」便可

成功後一切都有隻是當咱們點擊table圖標時並不會顯示table的實體,如咱們右擊相應的tablFind in Dragran時會出現以下提示:

這時候只須要在編輯區右鍵》DragranShow symbol》勾選須要的table實體再「OK」就闊以了

相關文章
相關標籤/搜索