Execl编写表结构导入PD,PD生成sqlserver脚本

Execl编写表结构导入PD,PD生成sqlserver脚本

一、编写Execl文档--设计表结构

 

 

二、通过代码导入PD

Option Explicit   
Dim mdl ' the current model 
Set mdl = ActiveModel 
If (mdl Is Nothing) Then   
  MsgBox "There is no Active Model" 
End If 
  
Dim bsheetname 
bsheetname="TB_SystemScreenData"

Dim HaveExcel 
Dim RQ  
RQ = vbYes
If RQ = vbYes Then  
   HaveExcel = True  
 Dim x1
 Set x1 = CreateObject("Excel.Application")
  x1.Workbooks.Open "E:\devlopment\webform\soft\2020Core框架\01开发源代码\Us.eIOP.Dev\Us.eIOP.Web\usdev\db\databaseDeveIOP.xlsx" 
  x1.Workbooks(1).Worksheets(bsheetname).Activate 
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 T_CName '表中文名称
Dim T_EName '表英文名称
Dim T_Comment '表说明

Dim C_Default '默认值
Dim C_NotNull '是否必填
Dim C_Primary '是否主键
Dim C_Code '字段名称

With x1.Workbooks(1).Worksheets(bsheetname)
T_CName = .Cells(1,2).Value
T_EName = .Cells(2,2).Value
T_Comment = .Cells(2,6).Value
End With 
 
'MsgBox "表名称:" + T_CName+""+T_EName, vbOK + vbInformation, "表" 


SET table = mdl.Tables.CreateNew 
        table.Name = T_CName 
        table.Code = T_EName 
        table.Comment = T_CName 

'on error Resume Next 
For rwIndex = 4 To 200 step 1   
    With x1.Workbooks(1).Worksheets(bsheetname)
   If .Cells(rwIndex, 3).Value = "" Then 
       Exit For 
   End If  
    If .Cells(rwIndex, 3).Value <> "" Then 
    colName = .Cells(rwIndex, 1).Value 
    
    C_Default = .Cells(rwIndex, 6).Value 
    C_NotNull =  .Cells(rwIndex, 5).Value 
    C_Primary=  .Cells(rwIndex, 4).Value 
    C_Code=  .Cells(rwIndex, 2).Value 
    
    set col = table.Columns.CreateNew  
    col.Name = colName
    col.Code = C_Code 
    col.Comment = colName  
    col.DataType = .Cells(rwIndex, 3).Value 
    
    IF C_Default<>"" THEN
      col.DefaultValueDisplayed = C_Default
     
    END IF
    IF C_NotNull= "" THEN
       col.Mandatory = True
    END IF
    IF C_Primary= "" THEN
       col.Primary = True
    END IF

    IF LCase(C_Code)="id" THEN
        col.Identity=True
        'col.Replica = True
    END IF
    
    
   End If 
  End With 
Next 
  
MsgBox "生成数据表结构:" + T_CName+","+T_EName, vbOK + vbInformation, "" 
 
Exit Sub 
End sub 
View Code

 

三、打开Power Designer粘贴

1、先把复制的东西修改下工作表名和execl所在位置路径(盘符)

 

2、粘贴 运行

 3、运行成功

 

 

4、左侧可以看到新引入的对应表 (选中拖到右边生成对应表描述)

 

 

四、pd中对应表生成sqlserver脚本

快捷方法 

(右键对应PD的框-如图的绿框,选SQL Preivew)  在Preview复制语句,在数据库执行就可创表成功

 

 

麻烦方法 

1、数据库(sqlserver)生成表

  

 

 2、设置保存地址和文件名

 

 3、默认会全选--所以需要取消全选-然后选择对应表

 

 4、选择对应表

 5、确定--确定前保证选择了一个表(一次生成多个暂时不清楚可以不可以--如果您知道可以留言告诉我哦!)

6、确定点击后弹出框可直接打开sql脚本,或者可以去保存路径下选择打开

6-1、直接打开

 6-2、保存路径下双击打开

7、复制脚本去sql对应数据库新建查询中执行-生成对应表

 

 

 

 

----------------------------------
---------------
---------
到这里就结束了哦☺!
有错误的地方可以在下面评论区告诉逐梦哦!
我们一起共同学习共同进步! ( ̄▽ ̄)~*
---------
---------------
----------------------------------

 

posted @ 2022-09-21 16:17  じ逐梦  阅读(123)  评论(0)    收藏  举报