Excelテーブル設計モデル回転powerdesigner pdmモデル
14679 ワード
文書ディレクトリ前言 コード 使用 注意 前言
最近excelを使用してテーブル構造を設計し、テーブル構造に基づいてpowerdesignerでpdmモデルを生成し、sql文を生成したいと考えています.最初は各テーブルをコピーして貼り付け、テーブルの数が多すぎるため、最終的には破棄され、スクリプトを使用して直接変換することを考慮します.ネット上で一般的にvbスクリプトを使ってこの機能を完成して、vbは私が学んだことがないため、他の人のコードの基礎の上で少し修正して、自分のために使います.コードは完璧ではありません.機能のニーズを満たすためだけに、エラーがあれば、ご了承ください.
コード#コード#
使用
Powerdesignerでpdmモデルを作成し、
に注意
表の例(画像を直接コピーしたいのですが、面倒なので、ここではexcelの代わりにmarkdownを使用します)ユーザー表:user
フィールド名
フィールドの説明
を選択します.
長さ
プライマリ・キー
ユニークかどうか
デフォルト
多値
id
ユニークID
varchar
32
はい
はい
login_id
ログインID
varchar
32
はい
username
ユーザー名
varchar
50
password
パスワード
varchar
50
status
≪ステータス|Status|emdw≫
int
1
1
0:無効1:有効
説明表は必ずしもこれに従う必要はありません.コードの論理を参考にして、自分でカスタマイズすることができます.
最近excelを使用してテーブル構造を設計し、テーブル構造に基づいてpowerdesignerでpdmモデルを生成し、sql文を生成したいと考えています.最初は各テーブルをコピーして貼り付け、テーブルの数が多すぎるため、最終的には破棄され、スクリプトを使用して直接変換することを考慮します.ネット上で一般的にvbスクリプトを使ってこの機能を完成して、vbは私が学んだことがないため、他の人のコードの基礎の上で少し修正して、自分のために使います.コードは完璧ではありません.機能のニーズを満たすためだけに、エラーがあれば、ご了承ください.
コード#コード#
Option Explicit
Dim excelPath,colNameIndex,colCommentIndex,colTypeIndex,colTypeLengthIndex,colIsPrimaryKeyIndex,colIsNotNullIndex,colDefaultValueIndex,colMultiValueIndex
'...... ......
excelPath = "D:\develop\ excel.xlsx" 'excel ( )
colNameIndex = 1 ' ( )
colCommentIndex = 2 ' ( )
colTypeIndex = 3 ' ( )
colTypeLengthIndex = 4 ' ( )
colIsPrimaryKeyIndex = 5 ' ( )
colIsNotNullIndex = 6 ' ( )
colDefaultValueIndex = 7 ' ( )
colMultiValueIndex = 8 ' ( )
'...... ......
Dim mdl,x1sApp,xlsWorkBook,xlsSheet
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
End If
' excel
Set x1sApp = CreateObject("Excel.Application")
Set xlsWorkBook = x1sApp.Workbooks.Open(excelPath)
Set xlsSheet = x1sApp.Workbooks(1).Worksheets("Sheet1")
a x1sApp,mdl,x1sApp,xlsWorkBook,xlsSheet
Sub a(x1, mdl,x1sApp,xlsWorkBook,xlsSheet)
Dim rowNum,table,col,count,rowCount
rowCount = xlsSheet.usedRange.Rows.Count
On Error Resume Next
'
For rowNum = 1 To rowCount
With xlsSheet
If .Cells(rowNum, 1).Value <> "" And .Cells(rowNum, 1).Value <> " " Then '
If .Cells(rowNum, 3).Value = "" Then ' ,
Set table = mdl.Tables.CreateNew '
table.Name = Split(.Cells(rowNum , 1).Value, ":")(1) '
table.Code = Split(.Cells(rowNum , 1).Value, ":")(1)
table.Comment = Split(.Cells(rowNum , 1).Value, ":")(0) '
count = count + 1
Else
'
Set col = table.Columns.CreateNew
'
col.Name = .Cells(rowNum, colNameIndex).Value
'
col.Code = .Cells(rowNum, colNameIndex).Value
'
col.DataType = .Cells(rowNum, colTypeIndex).Value
If CStr(.Cells(rowNum, colNameIndex).Value) <> "" And (CStr(.Cells(rowNum, colTypeIndex).Value) = "varchar" Or CStr(.Cells(rowNum, colTypeIndex).Value) = "char") Then
col.DataType = col.DataType + "(" + CStr(.Cells(rowNum, colTypeLengthIndex).Value) + ")"
End If
'
col.Comment = .Cells(rowNum, colCommentIndex).Value
If .Cells(rowNum, colMultiValueIndex).Value <> "" Then
col.Comment = col.Comment + "。" + .Cells(rowNum, colMultiValueIndex).Value
End If
'
If .Cells(rowNum, colIsPrimaryKeyIndex).Value = " " Then
col.Primary = True
End If
'
If .Cells(rowNum, colIsNotNullIndex).Value = " " Then
col.Mandatory = True
End If
'
If CStr(.Cells(rowNum, colDefaultValueIndex).Value) <> "" Then
col.DefaultValue = CStr(.Cells(rowNum, colDefaultValueIndex).Value)
End If
End If
End If
End With
Next
MsgBox " " + CStr(count) + " "
xlsWorkBook.Close
x1sApp.Quit
Set x1sApp = Nothing
Set xlsWorkBook = Nothing
Exit Sub
End Sub
使用
Powerdesignerでpdmモデルを作成し、
ctrl
+shift
+x
またはtools
->execute commands
->edit/run script
スクリプト入力ボックスを開き、貼り付けて実行します.に注意
表の例(画像を直接コピーしたいのですが、面倒なので、ここではexcelの代わりにmarkdownを使用します)ユーザー表:user
フィールド名
フィールドの説明
を選択します.
長さ
プライマリ・キー
ユニークかどうか
デフォルト
多値
id
ユニークID
varchar
32
はい
はい
login_id
ログインID
varchar
32
はい
username
ユーザー名
varchar
50
password
パスワード
varchar
50
status
≪ステータス|Status|emdw≫
int
1
1
0:無効1:有効
説明表は必ずしもこれに従う必要はありません.コードの論理を参考にして、自分でカスタマイズすることができます.