excel表结构生成powerDesigner模型,生成建表语句sql
一、excel表结构
二、PowerDesigner根据Excel导入模型
1、首先通过PowerDesigner创建物理模型
2、执行脚本,弹出 “生成成功”后即创建完成
工具->Execute commands->Edit/Run Script,脚本如下:
点击查看代码
' 第一行是表信息,依次是:表编码、表名称、表注释
' 第二行及后面为列信息,依次是:列编码、列名称、列数据类型、是否必填(M必填、O选填)、列注释
' Excel的sheet名称统一为sheet1
'开始
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 "D:\项目\天津一丰\DMS纳车数据连携字段(销售)2.xlsx" '指定 excel文档路径
x1.Workbooks(1).Worksheets("Sheet1").Activate '指定要打开的sheet名称
Else
HaveExcel = False
End If
a x1, mdl
sub a(x1, mdl)
dim rwIndex
dim tableName
dim colname
dim table
dim col
on error Resume Next
set table = mdl.Tables.CreateNew '创建一个 表实体
For rwIndex = 1 To 1000 '
With x1.Workbooks(1).Worksheets("Sheet1")
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End If
If rwIndex = 1 Then
' 表赋值
table.Code=.Cells(rwIndex, 1).Value
table.Name=.Cells(rwIndex, 2).Value
table.Comment=.Cells(rwIndex, 3).Value
Else
set col = table.Columns.CreateNew '创建一列/字段
col.Code = .Cells(rwIndex, 1).Value
col.Name = .Cells(rwIndex, 2).Value '指定列名
col.DataType = .Cells(rwIndex, 8).Value '指定列数据类型
col.Length = .Cells(rwIndex, 4).Value '列长度
col.Comment = .Cells(rwIndex, 5).Value '指定列说明
If .Cells(rwIndex, 6).Value = "M" Then
col.Primary = true '指定列是否为主键 true
End If
If .Cells(rwIndex, 7).Value = "TRUE" Then
col.Mandatory = true '指定列是否可空 true 为不可空
End If
If rwIndex = 2 Then
'col.Primary = true '指定主键
End If
End If
End With
Next
MsgBox "生成成功"
Exit Sub
End sub
三、生成sql语句,建表
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步