PowerDesigner导入Excel
1.编写测试EXCEL
2.修改脚本,指定excel所在路径及文件名
3.打开PowerDesigner,创建物理模型(Physical Data Model)
4.在PowerDesigner菜单栏中,依次点击“Tools ->Excute Commands->Edit/Run Script..”
在弹出窗口中点击Editor Menu,从中选择”Insert”
选择vb脚本并打开 脚本名称:测试导入excel脚本.vbs
点击Run,运行即可
备注:
1、”测试导入excel脚本.vbs“内容如下
Option Explicit '强制显示声明模块中的所有变量 '如模块中使用Option Explicit则须用 Dim、Private、Public、ReDim 或 Static 语句来显 式声明所有的变量。 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:/Test.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 '定义变量 Dim count '定义变量 Dim i 'on error Resume Next For i= 1 To x1.Workbooks(1).Sheets.Count '指定要导入的sheet的个数 For rwIndex = 2 To 100 step 1 '指定要遍历的Excel行标 If x1.Workbooks(1).Worksheets(i) Is Nothing Then Exit For Else With x1.Workbooks(1).Worksheets(i) '定义需要写入表结构所在的sheet 'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ),vbOK + vbInformation,"表" If .Cells(rwIndex,1).Value = "" Then Exit For End If If .Cells(rwIndex,3).Value = "" Then set table = mdl.Tables.CreateNew '创建一个实体表 table.Name = .Cells(rwIndex,1).Value table.Code = .Cells(rwIndex,2).Value 'table.DefaultValue = .cells(rwIndex,6).value count = count + 1 ElseIf rwIndex = 3 then Else colName = .Cells(rwIndex,1).Value Set col = table.Columns.CreateNew '创建一列/字段 'MsgBox .Cells(rwIndex,1).Value,"列" col.Name = .Cells(rwIndex,1).Value '指定列名 'MsgBox col.Name,"列" col.Code = .Cells(rwIndex,2).Value '指定字段名 col.Comment = .Cells(rwIndex,1).Value '指定列说明 col.DataType = .Cells(rwIndex,3).Value '指定列数据类型 ' col.DefaultValue = .Cells(rwIndex,6).Value '指定列数据类型 '设置主键 if.Cells(rwIndex,4).Value = "是" Then col.Primary = true End If '设置为空值 If.Cells(rwIndex,5).Value = "否" Then col.Mandatory = true End If End If End With End If Next Next MsgBox "生成数据表结构共计 " + CStr(count),"表" Exit Sub End sub
2、test.xlsx模板如下:
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|