Import the table structure designed from Excel to PowerDesigner.
1. Write an Excel template (the template and the following script need to be consistent)
2. Open PowerDesigner and create a Physical Data Model
3. In the PowerDesigner menu bar, click "Tools->Execute Commands->Edit/Run Script.."
'****************************************************************************** Option Explicit 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 " E:\Temp\1.xlsx " ' Specify the excel document path x1.Workbooks( 1 ).Worksheets( " Sheet1 " ).Activate ' Specify the name of the sheet to be opened 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 abc on error Resume Next ' -------------------------------- ' The following is to read excel, add table entity properties ' - ------------------------------- For rwIndex = 1 To 300 step 1 ' Specify the Excel row index to traverse due to the second The row is the table header , starting from row 1, see how many rows you design for this table "" Then ' Exit For ' End If ' If .Cells(rwIndex,1).Value = "Table" Then 'And .Cells(rwIndex,2).Value <> "" And .Cells(rwIndex,3).Value <> "" Then'The header in Excel Column 1 is the table name, 2 is the table name in Chinese, 3 is the table comment If rwIndex = 1 then ' the first row takes the table information set table = mdl.Tables.CreateNew ' create a table entity table.Code = .Cells(rwIndex, 2 ).Value ' Get the table name and code from excel table.Name = .Cells(rwIndex, 3 ).Value ' table.Comment = .Cells(rwIndex, 4 ).Value ' Specify the column description 'count = count + 1 Continue End If If.Cells(rwIndex, 1 ).Value = "" or .Cells(rwIndex, 1 ).Value = " Field " Then ' If the first column is empty, you can ignore it. Continue ' Here ignores empty rows and table name rows and headers Line Else set col =table.Columns.CreateNew ' Create a column/field col.Code = .Cells(rwIndex, 1 ).Value ' Specify the column code col.DataType = .Cells(rwIndex, 2 ).Value ' Specify the column data type If .Cells(rwIndex, 3 ).Value = " Y " Then 'Specify the primary key col.Primary = true End If If .Cells(rwIndex, 4 ).Value = " N " Then ' whether the specified column is nullable true is not nullable col.Mandatory = true End If col.Name = .Cells(rwIndex, 5 ).Value ' Specify the column name col.Comment = .Cells(rwIndex, 6 ).Value ' Specify the column description count = count + 1 End If 'If (.Cells(rwIndex,1).Value = "" And .Cells(rwIndex,2).Value = "" And .Cells(rwIndex,3).Value = "") Or (.Cells(rwIndex,1).Value <> "" And .Cells(rwIndex,2).Value = "" And .Cells(rwIndex,3).Value <> "")Then End With Next MsgBox " Generate data table structure total " + CStr (count), vbOK + vbInformation, " Table " Exit Sub End sub
4. Run the script
5. Check the table for fine-tuning