本文主要是介绍数据库通过pdm导出excel数据结构文档,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
数据库需要抽取数据至pdm展示,并且导出excel.找了一下汇总一起
1、数据库导出
plsql→tool→导出用户对象
选择导出用户对象
之后导出sql文件至指定路径
2、导出pdm
打开pdm
选择File->Reverse Engineer->datebase
创建后
引入导出的sql文件,等待加载完成即可
3、导出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/packageDim 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
即可导出excel
5、导出建库脚本
DataBase----->GenerDatabase----->选择路径的Directory 确定filename ---->Selection 全选表 然后确定生成建表SQL语句。
这篇关于数据库通过pdm导出excel数据结构文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!