前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >根据excel定义的表机构,导入powerdesigner

根据excel定义的表机构,导入powerdesigner

作者头像
用户5640963
发布2019-07-28 13:47:29
1.1K0
发布2019-07-28 13:47:29
举报
文章被收录于专栏:卯金刀GG卯金刀GG

在参考网上一些资料的基础上,自己整理。

定义的表机构

在powerdesigner调用的过程

工具>execute commands>edit/run script 执行以下代码

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 Dim strFileNameForFilter Dim cti strFileNameForFilter="文件的位置.xlsm" RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation") If RQ = vbYes Then HaveExcel = True ' Open & Create Excel Document Dim x1,xlBookFilter,xlSheetsFilter,xlSheetsFilterName ' Set x1 = CreateObject("Excel.Application") Set xlBookFilter = x1.Workbooks.Open(strFileNameForFilter) xlBookFilter.Activate Dim i, Count Count = xlBookFilter.Sheets.Count For i = 2 To Count 'xlSheetsFilter = xlBookFilter.Sheets(i) 'MsgBox xlSheetsFilter xlBookFilter.Sheets(i).Activate '指定要打开的sheet名称 cti = i a x1,mdl,cti Next Else HaveExcel = False End If

a x1, mdl, cti sub a(x1, mdl, cti) dim rwIndex dim tableName dim colname dim table dim col dim count on error Resume Next

set table = mdl.Tables.CreateNew '创建表 For rwIndex = 2 To 4 '指定要遍历的Excel行标 从第二行开始,遍历表名 With x1.Workbooks(1).Worksheets(i) If .Cells(rwIndex, 2).Value = "" Then '如果遍历到第二列为空,则退出 Exit For End If If .Cells(rwIndex, 2).Value = "表ID" Then table.Name = .Cells(rwIndex , 3).Value '指定表名,第三列的值 count = count + 1 elseIf .Cells(rwIndex, 2).Value = "表名" Then table.Code = .Cells(rwIndex , 3).Value '指定表中文名,第三列的值 else table.Comment = .Cells(rwIndex , 3).Value '指定表注释,第三列的值 End If End With Next

For rwIndex = 7 To 100 '指定要遍历的Excel行标 由于第1行是表头,从第2行开始 With x1.Workbooks(1).Worksheets(i) If .Cells(rwIndex, 3).Value = "" Then '如果遍历到第三列为空,则退出 Exit For End If

set col = table.Columns.CreateNew '创建一列/字段 col.Name = .Cells(rwIndex, 3).Value '指定列说明 col.Code = .Cells(rwIndex, 4).Value '指定列名 col.DataType = .Cells(rwIndex, 7).Value '指定列数据类型并且指定长度 col.Length = .Cells(rwIndex, 6).Value '指定列长度,这一列没用上 col.Comment = .Cells(rwIndex, 17).Value '指定列长度

If .Cells(rwIndex, 9).Value ="Y" then col.Mandatory = True '指定列是否可空,true不可为空 End If If .Cells(rwIndex, 10).Value ="1" then col.Primary = True '指定主键 End If

End With Next

'MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表"

Exit Sub End sub

注意:在PD中执行脚本的时候,如果提示:no Active Model,是因为没创建物理模型( Physical Data Model ),因为 不同的pd模型在使用时 是不同的编码-所以这里测试使用Physical Data Model

导入成功后,再生成可执行的ORA-sql的可执行语句,步骤:

菜单栏database->generation Database选择database-generation,导出可执行sql

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档