powerdesigner-Importing a table model from Excel

Source: Internet
Author: User
Tags powerdesigner

Near the process of using PD, there is a problem, that is, the class of fields, methods, types in Excel is organized, want to import into the PD directly generated class diagram. There are many ways to generate entity tables on the Web, so you can imitate and write a tool for generating class diagrams-extensions-scripts, or direct shortcut SHIFT + CTRL + X to open the Script window and execute the following code

1. Write Excel:

2. Open PowerDesigner, create a physical model (physical data model)- because different PD models are not encoded in use-so this test uses the physical data model

3. In the PowerDesigner menu bar, tap Tools->excute commands->edit/run Script.

 Option Explicit   DimOd.'The current modelSetMDL =ActivemodelIf(MDL is  Nothing) Then     MsgBox "there is no Active Model" End If   DimHaveexcelDimRQ RQ= vbyes'MsgBox ("is Excel installed on your machine?", vbYesNo + vbinformation, "confirmation")IfRQ = vbyes ThenHaveexcel=True  'Open & Create Excel Document DimX1'    SetX1 =CreateObject("Excel.Application") x1. Workbooks.Open"C:\Users\huage\Desktop\test\11.xlsx"X1. Workbooks (1). Worksheets ("Sheet1"). ActivateElseHaveexcel=False End Ifa x1, MDLSubA (X1,MDL)DimRwindexDimTableNameDimcolnameDimTableDimColDimCount'On error Resume Next forRwindex =1  to  + Step 1        withX1. Workbooks (1). Worksheets ("Sheet1")  'MsgBox "generated data table structure Total 1 =" +cstr (. Cells (2,2). Value), vbOK + vbinformation, "table"   If. Cells (Rwindex,1). Value =""  Then        Exit  for    End If    If. Cells (Rwindex,3). Value =""  Then     SetTable =MDL. Tables.createnew table. Name= . Cells (Rwindex,1). Value table. Code= . Cells (Rwindex,2). Value Count= Count +1     Elsecolname= . Cells (Rwindex,1). ValueSetCol =table. Columns.createnew'MsgBox. Cells (Rwindex, 1). Value, vbOK + vbinformation, "column"Col. Name =. Cells (Rwindex,1). Value'MsgBox Col. Name, vbOK + vbinformation, "column"Col. Code =. Cells (Rwindex,2). Value col.comment= . Cells (Rwindex,1). Value Col. DataType= . Cells (Rwindex,3). ValueEnd If   End  with Next   MsgBox "Generate data table structure Total"+CStr(count), vbOK + vbinformation,"Table"  Exit Sub End Sub 

The second type-there is a parse version (but there is a small bug written)

'StartOption ExplicitDimmdl'The current modelSetMDL =ActivemodelIf(MDL is  Nothing) ThenMsgBox "there is no Active Model"End IfDimHaveexcelDimRQRQ= vbyes'MsgBox ("is Excel installed on your machine?", vbYesNo + vbinformation, "confirmation")IfRQ = vbyes ThenHaveexcel=True'Open & Create Excel DocumentDimX1'SetX1 =CreateObject("Excel.Application") x1. Workbooks.Open"C:\Users\huage\Desktop\test\11.xlsx" 'Specify Excel document pathX1. Workbooks (1). Worksheets ("Sheet1"). Activate'Specifies the name of the sheet to openElseHaveexcel=FalseEnd Ifa x1, MDLSubA (x1, MDL)DimRwindexDimTableNameDimcolnameDimTableDimColDimCount on Error Resume NextSetTable = mdl. Tables.createnew'Create a table entityTable. Name ="Sheet1" 'Specify the table name, if it is available in the Excel document. Cells (Rwindex, 3). Value This specifiesTable. Code ="Sheet1" 'Specify table nameCount = Count +1 forRwindex =1  to  + 'Specifies the Excel row label to traverse because line 1th is the table header, starting at line 2nd withX1. Workbooks (1). Worksheets ("Sheet1")If. Cells (Rwindex,1). Value =""  ThenExit  forEnd IfSetcol = table. Columns.createnew'Create a column/field'MsgBox. Cells (Rwindex, 1). Value, vbOK + vbinformation, "column"If. Cells (Rwindex,3). Value =""  ThenCol. Name= . Cells (Rwindex,1). Value'Specify column nameElseCol. Name= . Cells (Rwindex,3). ValueEnd If'MsgBox Col. Name, vbOK + vbinformation, "column"Col. Code =. Cells (Rwindex,1). Value'Specify column nameCol. DataType =. Cells (Rwindex,2). Value'specifying column data typesCol.comment =. Cells (Rwindex,5). Value'Specifying column DescriptionsIf. Cells (Rwindex,4). Value ="No"  ThenCol. Mandatory=true 'Specifies whether the column is nullable true to be non-nullableEnd IfIfRwindex =2  ThenCol. Primary=true 'Specify primary KeyEnd IfEnd  withNextMsgBox "Generate data table structure Total"+CStr(count), vbOK + vbinformation,"Table"Exit SubEnd Sub

5. Testing
5.1 excel:c:\users\huage\desktop\test\11.xlsx Note that this path is consistent with the path in the script

5.2 Running the script
5.3 Checking the Import effect

powerdesigner-Importing a table model from Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.