• PowerDesigner数据库设计导出到Excel


    在PowerDesigner 中 ctrl+shift+x 弹出执行脚本界面,输入如下代码就会生成 Excel
     
    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
    代码一:所有的表在同一个 Sheet 页中
    '******************************************************************************
    '* File:     pdm2excel.txt
    '* Title:    pdm export to excel
    '* Purpose:  To export the tables and columns to Excel
    '* Model:    Physical Data Model
    '* Objects:  Table, Column, View
    '* Author:   ziyan
    '* Created:  2012-05-03
    '* Version:  1.0
    '******************************************************************************
    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, SHEET
     set EXCEL = CREATEOBJECT("Excel.Application")
     EXCEL.workbooks.add(-4167)'添加工作表
     EXCEL.workbooks(1).sheets(1).name ="test"
     set sheet = EXCEL.workbooks(1).sheets("test")
     
     ShowProperties Model, SHEET
     EXCEL.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 =true
     sheet.Columns(2).WrapText =true
     sheet.Columns(4).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
    '-----------------------------------------------------------------------------
    ' Show table properties
    '-----------------------------------------------------------------------------
    Sub ShowTable(tab, sheet)
       If IsObject(tab) Then
         Dim rangFlag
         rowsNum = rowsNum + 1
          ' Show properties
          Output "================================"
          sheet.cells(rowsNum, 1) = "实体名"
          sheet.cells(rowsNum, 2) =tab.name
          sheet.cells(rowsNum, 3) = ""
          sheet.cells(rowsNum, 4) = "表名"
          sheet.cells(rowsNum, 5) = tab.code
          sheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).Merge
          rowsNum = rowsNum + 1
          sheet.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 = 0
          for each col in tab.columns
            rowsNum = rowsNum + 1
            colsNum = colsNum + 1
          sheet.cells(rowsNum, 1) = col.name
          sheet.cells(rowsNum, 2) = col.comment
            sheet.cells(rowsNum, 3) = ""
          sheet.cells(rowsNum, 4) = col.name
          sheet.cells(rowsNum, 5) = col.code
          sheet.cells(rowsNum, 6) = col.datatype
          next
          sheet.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 + 1
     
          Output "FullDescription: "       + tab.Name
       End If
    End Sub

    代码二:每个表都会新建一个 Sheet 页,第一个 Sheet 页上是所有表的列表

    '****************************************************************************** 
    '* File:     pdm2excel.txt 
    '* Title:    pdm export to excel 
    '* Purpose:  To export the tables and columns to Excel 
    '* Model:    Physical Data Model 
    '* Objects:  Table, Column, View 
    '* Author:   Chirs 
    '* Created:  2015-01-28 
    '* Version:  1.0 
    '****************************************************************************** 
    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

     代码三:都在一页样式好看

    '******************************************************************************
    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, SHEET, SHEETLIST
          set EXCEL = CREATEOBJECT("Excel.Application")
          EXCEL.workbooks.add(-4167)'添加工作表
          EXCEL.workbooks(1).sheets(1).name ="表结构"
          set SHEET = EXCEL.workbooks(1).sheets("表结构")
          
          EXCEL.workbooks(1).sheets.add
          EXCEL.workbooks(1).sheets(1).name ="目录"
          set SHEETLIST = EXCEL.workbooks(1).sheets("目录")
          ShowTableList Model,SHEETLIST
    
          ShowProperties Model, SHEET,SHEETLIST
          
          
          EXCEL.workbooks(1).Sheets(2).Select
          EXCEL.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 =true
          sheet.Columns(2).WrapText =true
          sheet.Columns(4).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=0
       beginrow = rowsNum+1
       Dim rowIndex 
       rowIndex=3
       ' For each table
       output "begin"
       Dim tab
       For Each tab In mdl.tables
          ShowTable tab,sheet,rowIndex,sheetList
          rowIndex = rowIndex +1
       Next
       if mdl.tables.count > 0 then
            sheet.Range("A" & beginrow + 1 & ":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 + 1
          ' Show properties
          Output "================================"
          sheet.cells(rowsNum, 1) =tab.name
          sheet.cells(rowsNum, 1).HorizontalAlignment=3
          sheet.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=3
          sheet.Range(sheet.cells(rowsNum, 3),sheet.cells(rowsNum, 7)).Merge
          '设置超链接,从目录点击表名去查看表结构
          '字段中文名    字段英文名    字段类型    注释    是否主键    是否非空    默认值
          sheetList.Hyperlinks.Add sheetList.cells(rowIndex,2), "","表结构"&"!B"&rowsNum
          rowsNum = rowsNum + 1
          sheet.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=10
                Dim col ' running column
                Dim colsNum
                colsNum = 0
          for each col in tab.columns
            rowsNum = rowsNum + 1
            colsNum = colsNum + 1
              sheet.cells(rowsNum, 1) = col.name
            'sheet.cells(rowsNum, 3) = ""
              'sheet.cells(rowsNum, 4) = col.name
              sheet.cells(rowsNum, 2) = col.code
              sheet.cells(rowsNum, 3) = col.datatype
            sheet.cells(rowsNum, 4) = col.comment
              If col.Primary = true Then
            sheet.cells(rowsNum, 5) = "Y" 
            Else
            sheet.cells(rowsNum, 5) = " " 
            End If
            If col.Mandatory = true Then
            sheet.cells(rowsNum, 6) = "Y" 
            Else
            sheet.cells(rowsNum, 6) = " " 
            End If
            sheet.cells(rowsNum, 7) =  col.defaultvalue
          next
          sheet.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 = 10
          rowsNum = rowsNum + 2
          
          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=1
       ' For each table
       output "begin"
       SheetList.cells(rowsNo, 1) = "主题"
       SheetList.cells(rowsNo, 2) = "表中文名"
       SheetList.cells(rowsNo, 3) = "表英文名"
       SheetList.cells(rowsNo, 4) = "表说明"
       rowsNo = rowsNo + 1
       SheetList.cells(rowsNo, 1) = mdl.name
       Dim tab
       For Each tab In mdl.tables
         If IsObject(tab) Then
             rowsNo = rowsNo + 1
          SheetList.cells(rowsNo, 1) = ""
          SheetList.cells(rowsNo, 2) = tab.name
          SheetList.cells(rowsNo, 3) = tab.code
          SheetList.cells(rowsNo, 4) = tab.comment
         End If
       Next
        SheetList.Columns(1).ColumnWidth = 20 
          SheetList.Columns(2).ColumnWidth = 20 
          SheetList.Columns(3).ColumnWidth = 30 
         SheetList.Columns(4).ColumnWidth = 60 
       output "end"
    End Sub

     目录页可以跳转

    '******************************************************************************
    '* File:     Exported_Excel_page.vbs
    '* Purpose:  分目录递归,查找当前PDM下所有表,并导出Excel
    '* Title:    
    '* Category: 
    '* Version:  1.0
    '* Author:  787681084@qq.com
    '******************************************************************************
    
    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 
  • 相关阅读:
    struct tm->time() localtime() gmtime()
    解决VS2013中“This function or variable may be unsafe”的问题
    vm虚拟机三种网络模式
    vulnhub靶机-Raven解题思路
    vulnhub靶机-VulnOs:v2解题思路
    信息收集
    vulnhub靶机-SickOs1.2解题思路
    vulnhub靶机-SickOs解题思路
    vulnhub靶机-SkyTower解题思路
    vulnhub靶场-Stapler解题思路
  • 原文地址:https://www.cnblogs.com/cnsdhzzl/p/9765266.html
Copyright © 2020-2023  润新知