PowerDesigner导出表为Excel(转)
打开脚本运行器Ctrl+Shift+X
导出:
'****************************************************************************** Option ExplicitDim rowsNumrowsNum = 0 '----------------------------------------------------------------------------- ' Main function '----------------------------------------------------------------------------- ' Get the current active modelDim ModelSet Model = ActiveModelIf (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) ThenMsgBox "The current model is not an PDM model."Else' Get the tables collection'创建EXCEL APPdim beginrowDIM EXCEL, SHEET, SHEETLISTset EXCEL = CREATEOBJECT("Excel.Application")EXCEL.workbooks.add(-4167)'添加工作表EXCEL.workbooks(1).sheets(1).name ="表结构"set SHEET = EXCEL.workbooks(1).sheets("表结构")EXCEL.workbooks(1).sheets.addEXCEL.workbooks(1).sheets(1).name ="目录"set SHEETLIST = EXCEL.workbooks(1).sheets("目录")ShowTableList Model,SHEETLISTShowProperties Model, SHEET,SHEETLISTEXCEL.workbooks(1).Sheets(2).SelectEXCEL.visible = true'设置列宽和自动换行sheet.Columns(1).ColumnWidth = 20 sheet.Columns(2).ColumnWidth = 20 sheet.Columns(3).ColumnWidth = 20 sheet.Columns(4).ColumnWidth = 40 sheet.Columns(5).ColumnWidth = 10 sheet.Columns(6).ColumnWidth = 10 sheet.Columns(1).WrapText =truesheet.Columns(2).WrapText =truesheet.Columns(4).WrapText =true'不显示网格线EXCEL.ActiveWindow.DisplayGridlines = FalseEnd If '----------------------------------------------------------------------------- ' Show properties of tables '----------------------------------------------------------------------------- Sub ShowProperties(mdl, sheet,SheetList)' Show tables of the current model/packagerowsNum=0beginrow = rowsNum+1Dim rowIndex rowIndex=3' For each tableoutput "begin"Dim tabFor Each tab In mdl.tablesShowTable tab,sheet,rowIndex,sheetListrowIndex = rowIndex +1Nextif mdl.tables.count > 0 thensheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Groupend ifoutput "end" End Sub '----------------------------------------------------------------------------- ' Show table properties '----------------------------------------------------------------------------- Sub ShowTable(tab, sheet,rowIndex,sheetList)If IsObject(tab) ThenDim rangFlagrowsNum = rowsNum + 1' Show propertiesOutput "================================"sheet.cells(rowsNum, 1) =tab.namesheet.cells(rowsNum, 1).HorizontalAlignment=3sheet.cells(rowsNum, 2) = tab.code'sheet.cells(rowsNum, 5).HorizontalAlignment=3'sheet.cells(rowsNum, 6) = ""'sheet.cells(rowsNum, 7) = "表说明"sheet.cells(rowsNum, 3) = tab.comment'sheet.cells(rowsNum, 8).HorizontalAlignment=3sheet.Range(sheet.cells(rowsNum, 3),sheet.cells(rowsNum, 7)).Merge'设置超链接,从目录点击表名去查看表结构'字段中文名 字段英文名 字段类型 注释 是否主键 是否非空 默认值sheetList.Hyperlinks.Add sheetList.cells(rowIndex,2), "","表结构"&"!B"&rowsNumrowsNum = rowsNum + 1sheet.cells(rowsNum, 1) = "字段中文名"sheet.cells(rowsNum, 2) = "字段英文名"sheet.cells(rowsNum, 3) = "字段类型"sheet.cells(rowsNum, 4) = "注释"sheet.cells(rowsNum, 5) = "是否主键"sheet.cells(rowsNum, 6) = "是否非空"sheet.cells(rowsNum, 7) = "默认值"'设置边框sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Borders.LineStyle = "1"'sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"'字体为10号sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Font.Size=10Dim col ' running columnDim colsNumcolsNum = 0for each col in tab.columnsrowsNum = rowsNum + 1colsNum = colsNum + 1sheet.cells(rowsNum, 1) = col.name'sheet.cells(rowsNum, 3) = ""'sheet.cells(rowsNum, 4) = col.namesheet.cells(rowsNum, 2) = col.codesheet.cells(rowsNum, 3) = col.datatypesheet.cells(rowsNum, 4) = col.commentIf col.Primary = true Thensheet.cells(rowsNum, 5) = "Y" Elsesheet.cells(rowsNum, 5) = " " End IfIf col.Mandatory = true Thensheet.cells(rowsNum, 6) = "Y" Elsesheet.cells(rowsNum, 6) = " " End Ifsheet.cells(rowsNum, 7) = col.defaultvaluenextsheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Borders.LineStyle = "3" 'sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,9)).Borders.LineStyle = "3"sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Font.Size = 10rowsNum = rowsNum + 2Output "FullDescription: " + tab.NameEnd IfEnd Sub '----------------------------------------------------------------------------- ' Show List Of Table '----------------------------------------------------------------------------- Sub ShowTableList(mdl, SheetList)' Show tables of the current model/package Dim rowsNorowsNo=1' For each tableoutput "begin"SheetList.cells(rowsNo, 1) = "主题"SheetList.cells(rowsNo, 2) = "表中文名"SheetList.cells(rowsNo, 3) = "表英文名"SheetList.cells(rowsNo, 4) = "表说明"rowsNo = rowsNo + 1SheetList.cells(rowsNo, 1) = mdl.nameDim tabFor Each tab In mdl.tablesIf IsObject(tab) ThenrowsNo = rowsNo + 1SheetList.cells(rowsNo, 1) = ""SheetList.cells(rowsNo, 2) = tab.nameSheetList.cells(rowsNo, 3) = tab.codeSheetList.cells(rowsNo, 4) = tab.commentEnd IfNextSheetList.Columns(1).ColumnWidth = 20 SheetList.Columns(2).ColumnWidth = 20 SheetList.Columns(3).ColumnWidth = 30 SheetList.Columns(4).ColumnWidth = 60 output "end" End Sub
导入:
'****************************************************************************** '开始 Option Explicit Dim tab_name,tab_code,tab_comment Dim b_r, e_r, s_r, j, m, n Dim mdl ' the current model dim count Dim HaveExcel Dim RQ Dim file_name,WScript Set mdl = ActiveModel If (mdl Is Nothing) ThenMsgBox "There is no Active Model" End If RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation") If RQ = vbYes ThenHaveExcel = True' Open & Create Excel Document ElseHaveExcel = False End If file_name = selectFile() if file_name <> "" thenDim x1 'Set x1 = CreateObject("Excel.Application")x1.Workbooks.Open file_name '指定excel文档路径x1.Workbooks(1).Worksheets("表结构").Activate '指定要打开的sheet名称 j = 1 do while n < 11 if x1.Workbooks(1).Worksheets("表结构").cells(j,1).value <> "" then call a(x1, mdl, j, getRow(x1, j)) 'msgbox j & "--" & getRow(x1, j) count = count + 1 j = getRow(x1, j) n = 0 end if j = j + 1 n = n + 1 loop 'MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表 导入完毕!" MsgBox "生成数据表结构共计 " & CStr(count) & " 表导入完毕!" x1.Workbooks(1).close x1.quit else msgbox "没有选择文件!" end ifsub a(x1, mdl, r_0,r_9) dim rwIndex dim tableName dim colname dim table dim coltab_name = ucase(x1.Workbooks(1).Worksheets("表结构").cells(r_0,1).value) '指定表名,如果在Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定 tab_code = ucase(x1.Workbooks(1).Worksheets("表结构").cells(r_0,2).value) '指定表名 tab_comment = ucase(x1.Workbooks(1).Worksheets("表结构").cells(r_0,3).value)on error Resume Next set table = mdl.Tables.CreateNew '创建一个表实体 table.Name = tab_name table.Code = tab_code table.Comment = tab_commentFor rwIndex = r_0 + 2 To r_9 '指定要遍历的Excel行标 由于第1行是表头,从第2行开始With x1.Workbooks(1).Worksheets("表结构")If .Cells(rwIndex, 2).Value = "" ThenExit ForEnd Ifset col = table.Columns.CreateNew '创建一列/字段'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"If .Cells(rwIndex, 1).Value = "" Thencol.Name = ucase(.Cells(rwIndex, 2).Value) '指定列名Else col.Name = ucase(.Cells(rwIndex, 1).Value)End If'MsgBox col.Name, vbOK + vbInformation, "列"col.Code = ucase(.Cells(rwIndex, 2).Value) '指定列名col.DataType = ucase(.Cells(rwIndex, 3).Value) '指定列数据类型col.Comment = ucase(.Cells(rwIndex, 4).Value) '指定列说明If ucase(.Cells(rwIndex, 5).Value) = "Y" Thencol.Primary = true '指定主键col.defaultvalue = ucase(.Cells(rwIndex,7).value)End If If ucase(.Cells(rwIndex,6).value) = "Y" thencol.defaultvalue = ucase(.Cells(rwIndex,7).value)col.Mandatory = true End IfEnd With Next End subFunction getRow(x1, s_r) dim i, k k = s_r do while x1.Workbooks(1).Worksheets("表结构").cells(k,1).value <> "" k = k + 1 if x1.Workbooks(1).Worksheets("表结构").cells(k,1).value = "" then getRow = k - 1 exit function end if loop End Function Function SelectFile()Dim shell : Set shell = CreateObject("WScript.Shell")Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)Dim tempName : tempName = fso.GetTempName()Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")tempFile.Write _"<html>" & _"<head>" & _"<title>Browse</title>" & _"</head>" & _"<body>" & _"<input type='file' id='f' />" & _"<script type='text/javascript'>" & _"var f = document.getElementById('f');" & _"f.click();" & _"var shell = new ActiveXObject('WScript.Shell');" & _"shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\MsgResp', f.value);" & _"window.close();" & _"</script>" & _"</body>" & _"</html>"tempFile.Closeshell.Run tempFolder & "\" & tempName & ".hta", 0, TrueSelectFile = shell.RegRead("HKEY_CURRENT_USER\Volatile Environment\MsgResp")shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp" End Function
其它:
所有表同在一个Sheet
Option ExplicitDim rowsNumrowsNum = 0 '----------------------------------------------------------------------------- ' Main function '----------------------------------------------------------------------------- ' Get the current active model Dim Model Set Model = ActiveModel If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) ThenMsgBox "The current model is not an PDM model." Else' Get the tables collection'创建EXCEL APPdim beginrowDIM EXCEL, SHEETset EXCEL = CREATEOBJECT("Excel.Application")EXCEL.workbooks.add(-4167)'添加工作表EXCEL.workbooks(1).sheets(1).name ="test"set sheet = EXCEL.workbooks(1).sheets("test")ShowProperties Model, SHEETEXCEL.visible = true'设置列宽和自动换行sheet.Columns(1).ColumnWidth = 20 sheet.Columns(2).ColumnWidth = 40 sheet.Columns(4).ColumnWidth = 20 sheet.Columns(5).ColumnWidth = 20 sheet.Columns(6).ColumnWidth = 15 sheet.Columns(1).WrapText =truesheet.Columns(2).WrapText =truesheet.Columns(4).WrapText =trueEnd If '----------------------------------------------------------------------------- ' Show properties of tables '----------------------------------------------------------------------------- Sub ShowProperties(mdl, sheet)' Show tables of the current model/packagerowsNum=0beginrow = rowsNum+1' For each tableoutput "begin"Dim tabFor Each tab In mdl.tablesShowTable tab,sheetNextif mdl.tables.count > 0 thensheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Groupend ifoutput "end" End Sub '----------------------------------------------------------------------------- ' Show table properties '----------------------------------------------------------------------------- Sub ShowTable(tab, sheet)If IsObject(tab) ThenDim rangFlagrowsNum = rowsNum + 1' Show propertiesOutput "================================"sheet.cells(rowsNum, 1) = "实体名"sheet.cells(rowsNum, 2) =tab.namesheet.cells(rowsNum, 3) = ""sheet.cells(rowsNum, 4) = "表名"sheet.cells(rowsNum, 5) = tab.codesheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).MergerowsNum = rowsNum + 1sheet.cells(rowsNum, 1) = "属性名"sheet.cells(rowsNum, 2) = "说明"sheet.cells(rowsNum, 3) = ""sheet.cells(rowsNum, 4) = "字段中文名"sheet.cells(rowsNum, 5) = "字段名"sheet.cells(rowsNum, 6) = "字段类型"'设置边框sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Borders.LineStyle = "1"sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Borders.LineStyle = "1" Dim col ' running column Dim colsNum colsNum = 0for each col in tab.columnsrowsNum = rowsNum + 1colsNum = colsNum + 1sheet.cells(rowsNum, 1) = col.namesheet.cells(rowsNum, 2) = col.commentsheet.cells(rowsNum, 3) = ""sheet.cells(rowsNum, 4) = col.namesheet.cells(rowsNum, 5) = col.codesheet.cells(rowsNum, 6) = col.datatypenextsheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,2)).Borders.LineStyle = "2" sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,6)).Borders.LineStyle = "2"rowsNum = rowsNum + 1Output "FullDescription: " + tab.NameEnd If End Sub
每个表一个Sheet
Option Explicit Dim rowsNum rowsNum = 0 '----------------------------------------------------------------------------- ' Main function '----------------------------------------------------------------------------- ' Get the current active model Dim Model Set Model = ActiveModel If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then MsgBox "The current model is not an PDM model." Else ' Get the tables collection '创建EXCEL APP Dim beginrow Dim EXCEL, BOOK, SHEET Set EXCEL = CreateObject("Excel.Application") EXCEL.Visible = True Set BOOK = EXCEL.Workbooks.Add(-4167) '新建工作簿 BOOK.Sheets(1).Name = "数据库表结构" Set SHEET = EXCEL.workbooks(1).sheets("数据库表结构") ShowProperties Model, SHEET EXCEL.visible = true '设置列宽和自动换行 SHEET.Columns(1).ColumnWidth = 10 SHEET.Columns(2).ColumnWidth = 30 SHEET.Columns(3).ColumnWidth = 20 SHEET.Columns(1).WrapText =true SHEET.Columns(2).WrapText =true SHEET.Columns(3).WrapText =true End If '----------------------------------------------------------------------------- ' Show properties of tables '----------------------------------------------------------------------------- Sub ShowProperties(mdl, sheet) ' Show tables of the current model/package rowsNum=0 beginrow = rowsNum+1 ' For each table output "begin" Dim tab For Each tab In mdl.tables ShowTable tab,sheet Next if mdl.tables.count > 0 then sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group end if output "end" End Sub '----------------------------------------------------------------------------- ' 数据表查询 '----------------------------------------------------------------------------- Sub ShowTable(tab, sheet) If IsObject(tab) Then Dim rangFlag sheet.cells(1, 1) = "序号" sheet.cells(1, 2) = "表名" sheet.cells(1, 3) = "实体名" '设置边框 sheet.Range(sheet.cells(1, 1),sheet.cells(1, 3)).Borders.LineStyle = "1" '设置背景颜色 sheet.Range(sheet.cells(1, 1),sheet.cells(1, 3)).Interior.ColorIndex = "19" rowsNum = rowsNum + 1 sheet.cells(rowsNum+1, 1) = rowsNum sheet.cells(rowsNum+1, 2) = tab.code sheet.cells(rowsNum+1, 3) = tab.name '设置边框 sheet.Range(sheet.cells(rowsNum+1,1),sheet.cells(rowsNum+1,3)).Borders.LineStyle = "2" '增加Sheet BOOK.Sheets.Add , BOOK.Sheets(BOOK.Sheets.count) BOOK.Sheets(rowsNum+1).Name = tab.code Dim shtn Set shtn = EXCEL.workbooks(1).sheets(tab.code) '设置列宽和换行 shtn.Columns(1).ColumnWidth = 30 shtn.Columns(2).ColumnWidth = 20 shtn.Columns(3).ColumnWidth = 20 shtn.Columns(5).ColumnWidth = 30 shtn.Columns(6).ColumnWidth = 20 shtn.Columns(1).WrapText =true shtn.Columns(2).WrapText =true shtn.Columns(3).WrapText =true shtn.Columns(5).WrapText =true shtn.Columns(6).WrapText =true '设置列标题 shtn.cells(1, 1) = "字段中文名" shtn.cells(1, 2) = "字段名" shtn.cells(1, 3) = "字段类型" shtn.cells(1, 5) = tab.code shtn.cells(1, 6) = tab.Name '设置边框 shtn.Range(shtn.cells(1, 1),shtn.cells(1, 3)).Borders.LineStyle = "1" shtn.Range(shtn.cells(1, 5),shtn.cells(1, 6)).Borders.LineStyle = "1" '设置背景颜色 shtn.Range(shtn.cells(1, 1),shtn.cells(1, 3)).Interior.ColorIndex = "19" shtn.Range(shtn.cells(1, 5),shtn.cells(1, 6)).Interior.ColorIndex = "19" Dim col ' running column Dim colsNum Dim rNum colsNum = 0 rNum = 0 for each col in tab.columns rNum = rNum + 1 colsNum = colsNum + 1 shtn.cells(rNum+1, 1) = col.name shtn.cells(rNum+1, 2) = col.code shtn.cells(rNum+1, 3) = col.datatype next shtn.Range(shtn.cells(rNum-colsNum+2,1),shtn.cells(rNum+1,3)).Borders.LineStyle = "2" rNum = rNum + 1 Output "FullDescription: " + tab.Name End If End Sub
参考:
https://www.cnblogs.com/chenz/articles/3456340.html(以上内容转自此篇文章)
https://blog.csdn.net/Bin594505536/article/details/50517573(以上内容转自此篇文章)
==>如有问题,请联系我:easonjim#163.com,或者下方发表评论。<==
PowerDesigner导出表为Excel(转)相关推荐
- Powerdesigner导出为excel文档
1.首先打开Powerdesigner打开你需要导出的表 2.ctrl+shift+x快捷键打开脚本运行器复制以下脚本到脚本框中点击run执行(如下图) 3.导出成功会自动打开导出的Excel文件自己 ...
- oracle导出表为excel文件路径,Oracle导出数据为excel或文本文件
将oracle中表的数据导出为excel文件保存,在网上看了很多方法,总的来说有两种. 一是运用excel工具中通过ODBC连接oracle数据库,将文本导出. 一是通过oracle的命令导出.基本上 ...
- powerdesigner导出mysql数据库表结构到Excel
前提 要做数据源的整理,需要将Mysql数据库表的结构导出到Excel表里面做文档记录; 第一个Sheet是所有表格的列表,其他的Sheet是每一个表格的详细字段以及注释说明. 打开PowerDesi ...
- powerDesigner 导出excel
1.配置数据源 2.打开powedesigner ,创建Model 一.powerdesigner 连接 数据库, Database -> connect -> 二.更新数据库表结构到po ...
- PowerDesigner 将pdm模型表 用命令导出成Excel表格
PowerDesigner 将pdm模型表 用命令导出成Excel表格 使用步骤: 打开PowerDesigner 快捷键 Ctrl+Shift+X 直接将代码复制进去即可. 代码: '******* ...
- Web API-添加Swagger,SQL Server,记录并导出到Excel
目录 介绍 要求 1.创建一个新的Web API项目 2.将Swagger添加到项目 3.将项目连接到SQL Server数据库 4.登录到SQL Server 5.添加"导出到Excel& ...
- PDM数据表结构字段导出到excel
PowerDesigner表导出到excel 选中需要导出的tables ctrl + shift +x 然后运行脚本 '*************************************** ...
- plsql导出表结构到excel_将数据库中的表结构导出到excel中(写数据库设计说明书)...
这两天接到一个任务,写数据库设计说明书.很头疼啊~~ 网上翻阅了下范本,发现数据库设计说明书一般由数据库结构.数据字典.sql附件组成.这是我刚刚写好的数据库设计说明书. 这里记录下,方便自己下次查阅 ...
- powerDesigner 导出mysql的sql脚本,且包含注释
powerDesigner 导出mysql的sql脚本,且包含注释 为了和项目原有的数据库设计工具保持一致,近期使用了powerDesigner碰到了一些使用问题,汇总记录,希望对你有所帮助. 软件环 ...
最新文章
- Solaris 10 x86 上折腾Mono
- linux patches工具,patch工具入门
- sql存储过程的创建
- 安装慢_Origin平台安装更新慢的解决办法
- 构建之法第二章读后感
- scss 文件里的特殊符号 @ 和 @include 的用法
- HALCON示例程序measure_chip.hdev芯片封装检测
- Docker镜像构成和定制
- Linux系统中Oracle数据库使用SELECT语句检索数据(1)实例应用
- 如何使用功能性JavaScript编写经典游戏Snake并在浏览器中播放-完整的代码示例教程
- PostgreSQL / openGauss 数据库易犯的十个错误
- android 相对布局例子代码
- 中年程序员真的只能坐等被裁吗?
- java webtable_java winform开发:JTable详解
- unity控制相机移动
- ESP32-CAM 安信可
- 数据库系统--期末复习
- 【色彩管理】色彩管理之灰平衡
- window下搭建php环境
- 使用Pytorch框架
热门文章
- 2021中卫一中高考成绩查询,2021年宁夏高中排名及分数线 高考本科升学率排行榜...
- mysql sum函数返回类型_MySQL的sum函数返回的门类
- java 常量区存放 new_java---堆、栈、常量池的存储数据
- oracle19c监听服务启动失败,Oracle19c安装(有失败成功记录)
- vision软件_Roboguide软件:高速拾取仿真工作站相机与工具添加与配置
- ffmpeg编译android,FFMPEG Android(2) 编译编译静态ffmpeg可执行文件
- java this关键字表示当前对象,可以访问属性、方法、构造方法
- 三菱plcfx5u指令手册_从西门子200的PLC程序来看三菱FX5U的PLC程序
- 在java继承机制中 父类中的私有_Java中子类能继承父类的私有属性吗?
- EntityManager的使用