Power Designer vbs uses EXCEL to generate entities without entering them one by one.

Source: Internet
Author: User
 

After the CDM model is created

You can manually create an object, manually enter the corresponding attributes, convert it to a PDM model, and generate an SQL statement or other

When there are many attributes, we copy them one by one, which is relatively troublesome and cumbersome. I will do things after work .. Each entity has

100 .. Efficiency is extremely low. Therefore, you can use vbs to read Excel files in batches to directly produce objects. High efficiency. Let's talk about this.

Method.

1. After the CDM model is created, press the shortcut key Ctrl + Shift + X to open the vbs edit and run box.

2. Let's take a look at the code ..

'*************************************** ***************************************' * File: import_excel_to_excel.vbs '* purpose: Import EXCEL to create entity ''' * Title: import_cdm_to_excel.vbs' * Category: '* version: 1.0' * company: icegoly '* Time: '************************************** **************************************** 'excel format as follows 'field name Type field name is blank remarks table Object Name 'id Number ID is the identity of skey' skyel Ek '************************************** **************************************** 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 = 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: \ pd.xls" 'specifies the Excel file path x1.workbooks (1 ). worksheets ("sheet1 "). activate' specifies 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 nextset table = MDL. entities. createnew 'create a table entity '------------------------------' The following is to read two rows, six columns, three rows, and six columns in Excel to create a table entity '---------------------------- with x1.workbooks (1 ). worksheets ("sheet1") table. name =. cells (2, 6 ). value table. code =. cells (3, 6 ). value end with 'table. code = "am_cardinfo1" 'specify the table name COUNT = count + 1' ---------------------------------- 'The following is reading Excel' Add Table entity attribute 'tables for rwindex = 2 to 100' specifies the Excel file to be traversed because 1st rows are headers, starts with x1.workbooks (1) from row 2nd ). worksheets ("sheet1") if. cells (rwindex, 1 ). value = "" Then exit for end if set Col = table. attributes. createnew 'create a column/field if. cells (rwindex, 3 ). value = "" Then Col. name =. cells (rwindex, 1 ). value' specifies the column name else Col. name =. cells (rwindex, 3 ). value end if 'msgbox Col. name, vbok + vbinformation, "column" Col. code =. cells (rwindex, 1 ). value' specifies the column name Col. datatype =. cells (rwindex, 2 ). value' specifies the column data type Col. comment =. cells (rwindex, 5 ). value' specifies the column description if. cells (rwindex, 4 ). value = "yes" then Col. mandatory = true' specifies whether the column can be empty. True indicates that the end if 'if rwindex = 2 then' Col cannot be empty. primary = true 'specify primary key' end if end with next msgbox "generate data table structure total" + CSTR (count), vbok + vbinformation, "table" Exit sub end sub

3.

X1.workbooks. Open "C: \ pd.xls" 'specifies the Excel document path

That is, you can specify to open a specified Excel file.

4. the Excel format is as follows;

5. If there is no problem, you can run it ..

To download the corresponding table:

Http://115.com/file/c2i0wbtq

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.