zoukankan      html  css  js  c++  java
  • PowerDesigner从Excel导入表

    PowerDesigner要导入Excel,需要使用到VB语法,同时PowerDesigner集成了访问Excel的方法,VB代码如下:

    ' 第一行是表信息的描述,依次是:表名、表Code、表注释
    ' 第二行开始是列的描述,分别是:列名、列Code、列数据类型、列注释
    ' 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 "E:	able.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.Name=.Cells(rwIndex, 1).Value
                table.Code=.Cells(rwIndex, 2).Value
                table.Comment=.Cells(rwIndex, 3).Value
            Else        
                set col = table.Columns.CreateNew '创建一列/字段            
                
                col.Name = .Cells(rwIndex, 1).Value
                col.Code = .Cells(rwIndex, 2).Value '指定列名
                col.DataType = .Cells(rwIndex, 3).Value '指定列数据类型
                col.Comment = .Cells(rwIndex, 4).Value '指定列说明
                
                If .Cells(rwIndex, 4).Value = "" 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

    Excel的表结构如下:

     最后说明:

    1. 第一行是表信息的描述,依次是:表名、表Code、表注释
    2. 第二行开始是列的描述,分别是:列名、列Code、列数据类型、列注释
    3.Excel的sheet名称统一为sheet1

    4.Excel的位置是:E: able.xlsx

  • 相关阅读:
    后台跨域(CORS)
    golang 处理TCP粘包问题
    使用axios 发送ajax 下载文件
    Golang:在Redigo的RedisPool上选择DB
    puppeteer添加代理
    mongodb 权限操作
    alpine下安装icu-dev
    golang 导出CSV文件中文乱码的问题
    shell笔记
    Convert rune to int
  • 原文地址:https://www.cnblogs.com/duanjt/p/13339557.html
Copyright © 2011-2022 走看看