首页 > 其他分享 >powerDesigner导出Excel脚本

powerDesigner导出Excel脚本

时间:2023-12-06 16:01:46浏览次数:34  
标签:sheet rowsNum Excel cells 导出 powerDesigner Value catalog Cells

导出excel的脚本

如何将里面的表结构导出来到本地excel呢?

步骤:(1)打开powerDesigner,同时按住ctrl+shift+X,脚本框就会弹出来

同时按住ctrl+shift+X,脚本框就会弹出

 

(2)在脚本框中输入下面的代码(无需修改,直接复制粘贴就可),按下“Run”

    分目录递归,查找当前PDM下所有表,并导出Excel,脚本代码如下:  
'******************************************************************************
'* File:     Exported_Excel_page.vbs
'* Purpose:  分目录递归,查找当前PDM下所有表,并导出Excel
'******************************************************************************

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

'-----------------------------------------------------------------------------
' 主函数
'-----------------------------------------------------------------------------
' 获取当前活动模型
Dim mdl ' 当前的模型
Set mdl = ActiveModel
Dim EXCEL,catalog,sheet,catalogNum,rowsNum,linkNum
rowsNum = 1
catalogNum = 1
linkNum = 1

If (mdl Is Nothing) Then
    MsgBox "There is no Active Model"
Else
    SetCatalog
    ListObjects(mdl)
End If

'----------------------------------------------------------------------------------------------
' 子过程,用于扫描当前包并从当前包中打印对象的信息,然后对当前包的所有子包再次调用相同的子过程
'----------------------------------------------------------------------------------------------
Private Sub ListObjects(fldr)
    output "Scanning " & fldr.code
    Dim obj ' 运行对象
    For Each obj In fldr.children
        ' 调用子过程来打印对象上的信息
        DescribeObject obj
    Next
    ' 进入子包
    Dim f ' 运行文件夹
    For Each f In fldr.Packages
        '调用子程序扫描子程序包
        ListObjects f
    Next
End Sub

'-----------------------------------------------------------------------------
' 子过程,用于在输出中打印当前对象的信息
'-----------------------------------------------------------------------------
Private Sub DescribeObject(CurrentObject)
    if not CurrentObject.Iskindof(cls_NamedObject) then exit sub
    if CurrentObject.Iskindof(cls_Table) then 
        AddSheet CurrentObject.code
        ExportTable CurrentObject, sheet
        ExportCatalog CurrentObject
    else
        output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)   
    End if
End Sub

'----------------------------------------------------------------------------------------------
' 设置Excel的sheet页
'----------------------------------------------------------------------------------------------
Sub SetExcel()
    Set EXCEL= CreateObject("Excel.Application")

    ' 使Excel通过应用程序对象可见。
    EXCEL.Visible = True
    EXCEL.workbooks.add(-4167)'添加工作表
    EXCEL.workbooks(1).sheets(1).name ="pdm"
    set sheet = EXCEL.workbooks(1).sheets("pdm")

    ' 将一些文本放在工作表的第一行
    sheet.Cells(rowsNum, 1).Value = "表名"
    sheet.Cells(rowsNum, 2).Value = "表中文名"
    sheet.Cells(rowsNum, 3).Value = "表备注"
    sheet.Cells(rowsNum, 4).Value = "字段ID"
    sheet.Cells(rowsNum, 5).Value = "字段名"
    sheet.Cells(rowsNum, 6).Value = "字段中文名"
    sheet.Cells(rowsNum, 7).Value = "字段类型"
    sheet.Cells(rowsNum, 8).Value = "字段备注"
    sheet.cells(rowsNum, 9).Value = "主键"
    sheet.cells(rowsNum, 10).Value = "非空"
    sheet.cells(rowsNum, 11).Value = "默认值"
End Sub

'----------------------------------------------------------------------------------------------
' 导出目录结构
'----------------------------------------------------------------------------------------------
Sub ExportCatalog(tab)
    catalogNum = catalogNum + 1
    catalog.cells(catalogNum, 1).Value = tab.parent.name
    catalog.cells(catalogNum, 2).Value = tab.code
    catalog.cells(catalogNum, 3).Value = tab.comment
    '设置超链接
    catalog.Hyperlinks.Add catalog.cells(catalogNum,2), "",tab.code&"!A2"
End Sub 

'----------------------------------------------------------------------------------------------
' 导出sheet页
'----------------------------------------------------------------------------------------------
Sub ExportTable(tab, sheet)
    Dim col ' 运行列
    Dim colsNum
    colsNum = 0
    for each col in tab.columns
        colsNum = colsNum + 1
        rowsNum = rowsNum + 1
        sheet.Cells(rowsNum, 1).Value = tab.code
        'sheet.Cells(rowsNum, 2).Value = tab.name
        sheet.Cells(rowsNum, 2).Value = tab.comment
        'sheet.Cells(rowsNum, 4).Value = colsNum
        sheet.Cells(rowsNum, 3).Value = col.code
        'sheet.Cells(rowsNum, 4).Value = col.name
        sheet.Cells(rowsNum, 4).Value = col.datatype
        sheet.Cells(rowsNum, 5).Value = col.comment
        
        If col.Primary = true Then
            sheet.cells(rowsNum, 6) = "Y" 
        Else
            sheet.cells(rowsNum, 6) = "" 
        End If
        If col.Mandatory = true Then
            sheet.cells(rowsNum, 7) = "Y" 
        Else
            sheet.cells(rowsNum, 7) = "" 
        End If
        
        sheet.cells(rowsNum, 8).Value = col.defaultvalue
        '设置居中显示
        sheet.cells(rowsNum,6).HorizontalAlignment = 3
        sheet.cells(rowsNum,7).HorizontalAlignment = 3
    next
    output "Exported table: "+ +tab.Code+"("+tab.Name+")"
End Sub 

'----------------------------------------------------------------------------------------------
' 设置Excel目录页
'----------------------------------------------------------------------------------------------
Sub SetCatalog()
    Set EXCEL= CreateObject("Excel.Application")
    
    ' 使Excel通过应用程序对象可见。
    EXCEL.Visible = True
    EXCEL.workbooks.add(-4167)'添加工作表
    EXCEL.workbooks(1).sheets(1).name ="表结构"
    EXCEL.workbooks(1).sheets.add
    EXCEL.workbooks(1).sheets(1).name ="目录"
    set catalog = EXCEL.workbooks(1).sheets("目录")

    catalog.cells(catalogNum, 1) = "模块"
    catalog.cells(catalogNum, 2) = "表名"
    catalog.cells(catalogNum, 3) = "表注释"
    
    ' 设置列宽和自动换行
    catalog.Columns(1).ColumnWidth = 20
    catalog.Columns(2).ColumnWidth = 25
    catalog.Columns(3).ColumnWidth = 55
    
    '设置首行居中显示
    
    catalog.Range(catalog.cells(1,1),catalog.cells(1,3)).HorizontalAlignment = 3
    '设置首行字体加粗
    catalog.Range(catalog.cells(1,1),catalog.cells(1,3)).Font.Bold = True
End Sub 

'----------------------------------------------------------------------------------------------
' 新增sheet页
'----------------------------------------------------------------------------------------------
Sub AddSheet(sheetName)
    EXCEL.workbooks(1).Sheets(2).Select
    EXCEL.workbooks(1).sheets.add
    EXCEL.workbooks(1).sheets(2).name = sheetName
    set sheet = EXCEL.workbooks(1).sheets(sheetName)
    rowsNum = 1
    '将一些文本放在工作表的第一行
    sheet.Cells(rowsNum, 1).Value = "表名"
    'sheet.Cells(rowsNum, 2).Value = "表中文名"
    sheet.Cells(rowsNum, 2).Value = "表备注"
    'sheet.Cells(rowsNum, 4).Value = "字段ID"
    sheet.Cells(rowsNum, 3).Value = "字段名"
    'sheet.Cells(rowsNum, 4).Value = "字段中文名"
    sheet.Cells(rowsNum, 4).Value = "字段类型"
    sheet.Cells(rowsNum, 5).Value = "字段备注"
    sheet.cells(rowsNum, 6).Value = "主键"
    sheet.cells(rowsNum, 7).Value = "非空"
    sheet.cells(rowsNum, 8).Value = "默认值"
    
    '设置列宽
    sheet.Columns(1).ColumnWidth = 20
    sheet.Columns(2).ColumnWidth = 20
    sheet.Columns(3).ColumnWidth = 20
    sheet.Columns(4).ColumnWidth = 20
    sheet.Columns(5).ColumnWidth = 20
    sheet.Columns(6).ColumnWidth = 5
    sheet.Columns(7).ColumnWidth = 5
    sheet.Columns(8).ColumnWidth = 10

    '设置首行居中显示
    sheet.Range(sheet.cells(1,1),sheet.cells(1,8)).HorizontalAlignment = 3
    '设置首行字体加粗
    sheet.Range(sheet.cells(1,1),sheet.cells(1,8)).Font.Bold = True
    
    linkNum = linkNum + 1
    '设置超链接
    sheet.Hyperlinks.Add sheet.cells(1,1), "","目录"&"!B"&linkNum
End Sub 

 

(3)就开始自动生成excel,并自动生成数据

动图封面  

 

(4)导出excel结果如下:

 

标签:sheet,rowsNum,Excel,cells,导出,powerDesigner,Value,catalog,Cells
From: https://www.cnblogs.com/ios9/p/17879738.html

相关文章

  • 1、excel字符切割函数
    目录excel字符切割函数1、left函数2、RIGHT函数3、MID函数4、FIND函数5、SUBSTITUTE函数excel字符切割函数1、left函数从左边开始截取位数。=left("ABCD",2)输出:AB2、RIGHT函数从右边开始截取位数。=RIGHT("ABCD",2)输出:CD3、MID函数从左边任意3位置(包含)开始截取,连......
  • VBA-Excel数组应用
    1)数组创建A类:动态数组Dimarr()  创建一个动态变量数组,不受长度/数据类型受制B类:静态数组Dimarr(5) asstring  创建一个一维数组,下标从0开始,最大下标值为5Dimarr(3,3)asInteger创建一个二维数组,开始arr(0,0),最后一个arr(3,3)Dimarr=array(1,2,3)创建一......
  • VBA-Excel程序控制语法
    1、If…Then语句 SubSayHello1()  IfTime<0.5ThenMsgBox"早上好!"  IfTime>=0.5ThenMsgBox"下午好!"EndSubSubSayHello2()  IfTime<0.5Then    MsgBox"早上好!"  Else    MsgBox"下午好!"  EndIf......
  • DevExpress WinForms Pivot Grid组件,一个类似Excel的数据透视表控件(一)
    界面控件DevExpressWinForms的PivotGrid组件是一个类似Excel的数据透视表控件,用于多维(OLAP)数据分析和跨选项卡报表。众多的布局自定义选项使您可以完全控制其UI,无与伦比的以用户为中心的功能使其易于部署。DevExpressWinForms有180+组件和UI库,能为WindowsForms平台创建具有......
  • 使用ThinkPHP框架根据Excel内容批量处理图片名称详解记录
    ThinkPHP依赖以下环境Nginx+PHP,建议提前装好Composer,PHP、Composer需要设置好系统环境变量。1.通过Composer安装Laravel框架composercreate-projecttopthink/thinkthinkphp6启动服务测试cdthinkphp6phpthinkrun然后就可以在浏览器中访问http://localhost:8000如果不能显示......
  • excel 循环
    testxlsx=pd.ExcelWriter('test.xlsx')foriinplat_360:forjinrange(0,len(needcolumns)):ifneedcolumns[j]!='省份':table=pd.pivot_table(data_cgm_360_copy_dropdup[data_cgm_360_copy_dropdup.plati],index='等级',columns=needcolum......
  • easypoi导出带动态下拉框
    涉及无限极分类实现ProductExcel.javapackageio.renren.modules.product.excel;importcn.afterturn.easypoi.excel.annotation.Excel;importio.renren.modules.product.dto.ProductBarDTO;importio.swagger.annotations.ApiModelProperty;importlombok.Data;impor......
  • Excel判断日期是否是工作日的实现(排除节假日,加上补班日)
     实现思路:工作日= 【周一到周五(排除节假日)或者补班日】公式编写:1.周一到周五判断WEEKDAY(A2,2) 获取该日期是星期几(返回:1-7),那么周一到周五就是<62.非节假日判断COUNTIF($G$2:$G$398,A2)=0统计该日期在指定区域$G$2:$G$398中出现的次数,非节假日就是未出现,出现......
  • 基础lucksheet实现前端导出excel文件
    文章参考:https://blog.csdn.net/csdn_lsy/article/details/1071797081.引入两个插件,其中exceljs负责将lucksheet的数据格式转化成excel的buffer流,file-saver负责将buffer转成blob文件流导出。npminstallexceljsnpminstallfile-saver2.代码实现constExcel=require('......
  • kubectl获取ConfigMap导出YAML时如何忽略某些字段
    前言:当我们在使用Kubernetes时,常常需要通过kubectl命令行工具来管理资源。有时我们也想将某个资源的配置导出为YAML文件,这样做有助于版本控制和资源的迁移。然而,默认情况下,使用kubectlget命令导出资源配置会包含一些元数据字段:如**annotations****,**creationTimestamp**,**r......