今天项目做设计,客户要看数据设计,需要到处Excel表格。去网上搜索下,把使用总结如下:
已经完成设计的pd设计
打开pd,快捷键Ctrl + Shift + X或者Tools>Exectue Commands > Edit/Run Script

代码一:到处到单个excel中 推荐使用这个

'******************************************************************************
Option Explicit
Dim rowsNum
rowsNum =
'-----------------------------------------------------------------------------
' 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, SHEET, SHEETLIST
set EXCEL = CREATEOBJECT("Excel.Application")
EXCEL.workbooks.add(-)'添加工作表
EXCEL.workbooks().sheets().name ="表结构"
set SHEET = EXCEL.workbooks().sheets("表结构") EXCEL.workbooks().sheets.add
EXCEL.workbooks().sheets().name ="目录"
set SHEETLIST = EXCEL.workbooks().sheets("目录")
ShowTableList Model,SHEETLIST ShowProperties Model, SHEET,SHEETLIST EXCEL.workbooks().Sheets().Select
EXCEL.visible = true
'设置列宽和自动换行
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().ColumnWidth =
sheet.Columns().WrapText =true
sheet.Columns().WrapText =true
sheet.Columns().WrapText =true
'不显示网格线
EXCEL.ActiveWindow.DisplayGridlines = False End If
'-----------------------------------------------------------------------------
' Show properties of tables
'-----------------------------------------------------------------------------
Sub ShowProperties(mdl, sheet,SheetList)
' Show tables of the current model/package
rowsNum=
beginrow = rowsNum+
Dim rowIndex
rowIndex=
' For each table
output "begin"
Dim tab
For Each tab In mdl.tables
ShowTable tab,sheet,rowIndex,sheetList
rowIndex = rowIndex +
Next
if mdl.tables.count > then
sheet.Range("A" & beginrow + & ":A" & rowsNum).Rows.Group
end if
output "end"
End Sub
'-----------------------------------------------------------------------------
' Show table properties
'-----------------------------------------------------------------------------
Sub ShowTable(tab, sheet,rowIndex,sheetList)
If IsObject(tab) Then
Dim rangFlag
rowsNum = rowsNum +
' Show properties
Output "================================"
sheet.cells(rowsNum, ) =tab.name
sheet.cells(rowsNum, ).HorizontalAlignment=
sheet.cells(rowsNum, ) = tab.code
'sheet.cells(rowsNum, 5).HorizontalAlignment=3
'sheet.cells(rowsNum, 6) = ""
'sheet.cells(rowsNum, 7) = "表说明"
sheet.cells(rowsNum, ) = tab.comment
'sheet.cells(rowsNum, 8).HorizontalAlignment=3
sheet.Range(sheet.cells(rowsNum, ),sheet.cells(rowsNum, )).Merge
'设置超链接,从目录点击表名去查看表结构
'字段中文名 字段英文名 字段类型 注释 是否主键 是否非空 默认值
sheetList.Hyperlinks.Add sheetList.cells(rowIndex,), "","表结构"&"!B"&rowsNum
rowsNum = rowsNum +
sheet.cells(rowsNum, ) = "字段中文名"
sheet.cells(rowsNum, ) = "字段英文名"
sheet.cells(rowsNum, ) = "字段类型"
sheet.cells(rowsNum, ) = "注释"
sheet.cells(rowsNum, ) = "是否主键"
sheet.cells(rowsNum, ) = "是否非空"
sheet.cells(rowsNum, ) = "默认值"
'设置边框
sheet.Range(sheet.cells(rowsNum-, ),sheet.cells(rowsNum, )).Borders.LineStyle = ""
'sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"
'字体为10号
sheet.Range(sheet.cells(rowsNum-, ),sheet.cells(rowsNum, )).Font.Size=
Dim col ' running column
Dim colsNum
colsNum =
for each col in tab.columns
rowsNum = rowsNum +
colsNum = colsNum +
sheet.cells(rowsNum, ) = col.name
'sheet.cells(rowsNum, 3) = ""
'sheet.cells(rowsNum, 4) = col.name
sheet.cells(rowsNum, ) = col.code
sheet.cells(rowsNum, ) = col.datatype
sheet.cells(rowsNum, ) = col.comment
If col.Primary = true Then
sheet.cells(rowsNum, ) = "Y"
Else
sheet.cells(rowsNum, ) = " "
End If
If col.Mandatory = true Then
sheet.cells(rowsNum, ) = "Y"
Else
sheet.cells(rowsNum, ) = " "
End If
sheet.cells(rowsNum, ) = col.defaultvalue
next
sheet.Range(sheet.cells(rowsNum-colsNum+,),sheet.cells(rowsNum,)).Borders.LineStyle = ""
'sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,9)).Borders.LineStyle = "3"
sheet.Range(sheet.cells(rowsNum-colsNum+,),sheet.cells(rowsNum,)).Font.Size =
rowsNum = rowsNum + Output "FullDescription: " + tab.Name
End If End Sub
'-----------------------------------------------------------------------------
' Show List Of Table
'-----------------------------------------------------------------------------
Sub ShowTableList(mdl, SheetList)
' Show tables of the current model/package
Dim rowsNo
rowsNo=
' For each table
output "begin"
SheetList.cells(rowsNo, ) = "主题"
SheetList.cells(rowsNo, ) = "表中文名"
SheetList.cells(rowsNo, ) = "表英文名"
SheetList.cells(rowsNo, ) = "表说明"
rowsNo = rowsNo +
SheetList.cells(rowsNo, ) = mdl.name
Dim tab
For Each tab In mdl.tables
If IsObject(tab) Then
rowsNo = rowsNo +
SheetList.cells(rowsNo, ) = ""
SheetList.cells(rowsNo, ) = tab.name
SheetList.cells(rowsNo, ) = tab.code
SheetList.cells(rowsNo, ) = tab.comment
End If
Next
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
SheetList.Columns().ColumnWidth =
output "end"
End Sub

代码二:将结构到处到多个sheet中

Option Explicit
Dim rowsNum
rowsNum =
'-----------------------------------------------------------------------------
' 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(-) '新建工作簿 BOOK.Sheets().Name = "数据库表结构"
Set SHEET = EXCEL.workbooks().sheets("数据库表结构") ShowProperties Model, SHEET
EXCEL.visible = true
'设置列宽和自动换行
SHEET.Columns().ColumnWidth =
SHEET.Columns().ColumnWidth =
SHEET.Columns().ColumnWidth = SHEET.Columns().WrapText =true
SHEET.Columns().WrapText =true
SHEET.Columns().WrapText =true End If '-----------------------------------------------------------------------------
' Show properties of tables
'-----------------------------------------------------------------------------
Sub ShowProperties(mdl, sheet)
' Show tables of the current model/package
rowsNum=
beginrow = rowsNum+
' For each table
output "begin"
Dim tab
For Each tab In mdl.tables
ShowTable tab,sheet
Next
if mdl.tables.count > then
sheet.Range("A" & beginrow + & ":A" & rowsNum).Rows.Group
end if
output "end"
End Sub '-----------------------------------------------------------------------------
' 数据表查询
'-----------------------------------------------------------------------------
Sub ShowTable(tab, sheet)
If IsObject(tab) Then
Dim rangFlag
sheet.cells(, ) = "序号"
sheet.cells(, ) = "表名"
sheet.cells(, ) = "实体名"
'设置边框
sheet.Range(sheet.cells(, ),sheet.cells(, )).Borders.LineStyle = ""
'设置背景颜色
sheet.Range(sheet.cells(, ),sheet.cells(, )).Interior.ColorIndex = "" rowsNum = rowsNum +
sheet.cells(rowsNum+, ) = rowsNum
sheet.cells(rowsNum+, ) = tab.code
sheet.cells(rowsNum+, ) = tab.name
'设置边框
sheet.Range(sheet.cells(rowsNum+,),sheet.cells(rowsNum+,)).Borders.LineStyle = "" '增加Sheet
BOOK.Sheets.Add , BOOK.Sheets(BOOK.Sheets.count)
BOOK.Sheets(rowsNum+).Name = tab.code Dim shtn
Set shtn = EXCEL.workbooks().sheets(tab.code)
'设置列宽和换行
shtn.Columns().ColumnWidth =
shtn.Columns().ColumnWidth =
shtn.Columns().ColumnWidth =
shtn.Columns().ColumnWidth =
shtn.Columns().ColumnWidth = shtn.Columns().WrapText =true
shtn.Columns().WrapText =true
shtn.Columns().WrapText =true
shtn.Columns().WrapText =true
shtn.Columns().WrapText =true '设置列标题
shtn.cells(, ) = "字段中文名"
shtn.cells(, ) = "字段名"
shtn.cells(, ) = "字段类型"
shtn.cells(, ) = tab.code
shtn.cells(, ) = tab.Name
'设置边框
shtn.Range(shtn.cells(, ),shtn.cells(, )).Borders.LineStyle = ""
shtn.Range(shtn.cells(, ),shtn.cells(, )).Borders.LineStyle = ""
'设置背景颜色
shtn.Range(shtn.cells(, ),shtn.cells(, )).Interior.ColorIndex = ""
shtn.Range(shtn.cells(, ),shtn.cells(, )).Interior.ColorIndex = "" Dim col ' running column
Dim colsNum
Dim rNum
colsNum =
rNum =
for each col in tab.columns
rNum = rNum +
colsNum = colsNum + shtn.cells(rNum+, ) = col.name
shtn.cells(rNum+, ) = col.code
shtn.cells(rNum+, ) = col.datatype
next
shtn.Range(shtn.cells(rNum-colsNum+,),shtn.cells(rNum+,)).Borders.LineStyle = ""
rNum = rNum + Output "FullDescription: " + tab.Name End If
End Sub

PowerDesigner 中模型设计导出Excel表格的更多相关文章

  1. Vue中导出Excel表格方法

    本文记录一下在Vue中实现导出Excel表格的做法.参考度娘上各篇博客,最后实现功能 Excel表格,我的后端返回的是数据流,然后文件名是放进了content-disposition中,前端进行获取. ...

  2. java中使用jxl导出Excel表格详细通用步骤

    该方法一般接收两个参数,response和要导出的表格内容的list. 一般我们将数据库的数据查询出来在页面进行展示,根据用户需求,可能需要对页面数据进行导出. 此时只要将展示之前查询所得的数据放入s ...

  3. js导出excel表格中较长数字串会变成科学计数法问题

    在做项目中,遇到导出excel表格时,银行账户号数字过长,导出的数字串变为计数法形式,如下图: 网上搜到解决方法,粘贴到这以供学习.不断更新. 原博地址:http://www.cnblogs.com/ ...

  4. html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式

    先上代码   <script type="text/javascript" language="javascript">   var idTmr; ...

  5. vue中导出Excel表格

    项目中我们可能会碰到导出Excel文件的需求,一般后台管理系统中居多,将table中展示的数据导出保存到本地.当然我们也可以通过一些处理来修改要导出的数据格式,具体需求具体对待. 1.首先我们需要安装 ...

  6. 在vue中导出excel表格

    初学者学习vue开发,想把前端项目中导出Excel表格,查了众多帖子,踩了很多坑,拿出来与大家分享一下经验. 安装依赖 //npm npm install file-saver -S npm inst ...

  7. NPOI_winfrom导出Excel表格(二)(直接打开Excel软件,将数据填充在当前的sheet中)

    //// 存储路径弹框选择 SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = "xls&qu ...

  8. spring mvc项目中导出excel表格简单实现

    查阅了一些资料,才整理出spring mvc 项目导出excel表格的实现,其实很是简单,小计一下,方便以后查阅,也希望帮助有需要的朋友. 1.导入所需要依赖(Jar包).我使用的是maven,所以坐 ...

  9. PHP导入导出excel表格图片(转)

    写excel的时候,我用过pear的库,也用过pack压包的头,同样那些利用smarty等作的简单替换xml的也用过,csv的就更不用谈了.呵呵.(COM方式不讲了,这种可读的太多了,我也写过利用wp ...

随机推荐

  1. Django restful

    1.restful api的规范 API与用户的通信协议,总是使用HTTPs协议. 域名  https://api.example.com                         尽量将API ...

  2. [ZJOI2016]大森林

    Description: 小Y家里有一个大森林,里面有n棵树,编号从1到n 0 l r 表示将第 l 棵树到第 r 棵树的生长节点下面长出一个子节点,子节点的标号为上一个 0 号操作叶子标号加 1(例 ...

  3. 基于zookeeper的高可用Hadoop HA集群安装

    (1)hadoop2.7.1源码编译 http://aperise.iteye.com/blog/2246856 (2)hadoop2.7.1安装准备 http://aperise.iteye.com ...

  4. learning to generate question headlines 讲座

    渣排版预警! 出发点 新闻用户为什么会点: 主观:用户兴趣/热点事件 客观:新闻标题(新闻入口)/新闻内容(更简单,更有趣) 标题分类: surprise,好奇,负例,数字,你,客观的描述,问题的形式 ...

  5. opencv+python 自动绿帽机

    具体内容,直接看注释吧,该注释的我都注释掉了. # coding:utf-8 import cv2 # 待检测的图片路径 imagepath = r'D://greenhat//2.jpg' # 获取 ...

  6. 百度杯 ctf 九月场---Text

    一看题目发现善于查资料就行了,那估计就是以前的漏洞,需要百度搜一下,果然是海洋cms的漏洞!这个漏洞是前台getshell漏洞,seach漏洞,该漏洞成因在于search.php没有对用户输入内容进行 ...

  7. python之面向对象的程序设计

    一.什么是面向对象的程序设计 面向过程的程序设计的核心是过程,过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点是:极大的降低了程序的复杂度 缺点是: ...

  8. Docker 常用命令(四)

    1. 查看容器中的进程信息: docker top 772d23 查看容器的详细信息: docker inspect 772d23 持续更新日志 docker logs -f 7732dx

  9. cto职责

    http://www.sohu.com/a/209574647_505825 https://mp.weixin.qq.com/s?src=3&timestamp=1513066866& ...

  10. 法嵌入互操作类型“SHDocVw.ShellWindowsClass”请改用适用的接口-解决方法

    点DLL名字,---属性----------嵌入互操作类型(设置为false)