28. 基于PowerDesigner通过Excel批量生成Mysql脚本语句
1. 打开PownerDesigner
进入路径:Tools - > Execute Commands - > Edit/Run Script
打开文件夹,选择 对应的 *.vbs 执行脚本
根据Excel 批量执行脚本:
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:\IdeaProjects\ajoy\ajoy_doc\02-设计\02-数据库表结构\A-Joy产品项目数据库表设计 - v1.0.xlsx" ' x1.Workbooks(1).Worksheets("批量生成表").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 abc on error Resume Next '-------------------------------- '下面是读取excel,添加表实体属性 '-------------------------------- For rwIndex = 1 To 1350 ' With x1.Workbooks(1).Worksheets("批量生成表")' If .Cells(rwIndex,1).Value <> "" And .Cells(rwIndex,2).Value = "" And .Cells(rwIndex,3).Value <> "" Then' set table = mdl.Tables.CreateNew ' table.Code = .Cells(rwIndex,1).Value' table.Name = .Cells(rwIndex,3).Value' table.Comment = .Cells(rwIndex,4).Value ' count = count + 1 Continue 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 If .Cells(rwIndex,2).Value = "" or .Cells(rwIndex,1).Value = "字段" Then ' continue ' Else set col =table.Columns.CreateNew ' col.Code = .Cells(rwIndex, 1).Value ' col.DataType = .Cells(rwIndex, 2).Value ' If.Cells(rwIndex, 3).Value = "TRUE" Then' col.Primary =true End If If.Cells(rwIndex, 4).Value = "FALSE" Then' col.Mandatory =true End If col.Name = .Cells(rwIndex, 5).Value ' col.Comment = .Cells(rwIndex, 5).Value ' End If End With Next MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表" Exit Sub End sub
对应的Excel格式: