powerdesigner导出excel数据字典

执行方法:Tools -> Execute COmmands -> Edit/Run Script 或者用快捷键也可以:ctr+shift+X

'******************************************************************************  
Option Explicit  
   Dim rowsNum  
   rowsNum = 2

Dim Model  
Set Model = ActiveModel  
If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then  
  Debug.print "null"
Else  
    ' Get the tables collection  
    '创建EXCEL APP  
    dim beginrow  
    DIM EXCEL, SHEET  
    set EXCEL = CREATEOBJECT("Excel.Application")  
    EXCEL.workbooks.add  '添加工作表  
    SET sheet = EXCEL.workbooks(1).sheets(1)  
    sheet.name ="数据字典"  
   
   sheet.Range(sheet.cells(1, 1),sheet.cells(1, 9)).Merge
   sheet.cells(1, 1) ="淘宝服装店地址:http://52sunan.taobao.com"
   sheet.Range(sheet.cells(1, 1),sheet.cells(1, 9)).Interior.Color=rgb(146,208,80)
   
   rowsNum=2  
   beginrow = rowsNum+1  

   Dim tab  
   For Each tab In Model.tables  
      TableLoop tab,SHEET  
   Next
    
    
    EXCEL.visible = true  
    '设置列宽和自动换行  
    sheet.Columns(1).ColumnWidth  =10
    sheet.Columns(2).ColumnWidth  =15
    sheet.Columns(4).ColumnWidth  =20
    sheet.Columns(5).ColumnWidth  =15
    sheet.Columns(6).ColumnWidth  =15
    
    sheet.Columns("C:C").EntireColumn.AutoFit
    sheet.Columns("i:i").EntireColumn.AutoFit    
 End If  

Sub TableLoop(tab, sheet)  
   If IsObject(tab) Then  
      Dim rangFlag  
      rowsNum = rowsNum + 1  
      
      sheet.cells(rowsNum, 1) = "表名"  
      sheet.Range(sheet.cells(rowsNum, 2),sheet.cells(rowsNum, 9)).Merge
      sheet.cells(rowsNum, 2)=tab.code
      sheet.Range(sheet.cells(rowsNum, 1),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"
      sheet.Range(sheet.cells(rowsNum, 1),sheet.cells(rowsNum, 9)).Interior.Color=rgb(141,180,226)
      sheet.Range(sheet.cells(rowsNum, 1),sheet.cells(rowsNum, 9)).Borders.Weight ="3"
      
      rowsNum = rowsNum + 2
      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.cells(rowsNum, 8) = "默认值"  
      sheet.cells(rowsNum, 9) = "说明"  
      sheet.Range(sheet.cells(rowsNum,1),sheet.cells(rowsNum,9)).Interior.Color=rgb(166,166,166)
      
      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.code
         sheet.cells(rowsNum, 3) = col.datatype
         sheet.cells(rowsNum, 4) = IIF(col.Length<>0,col.Length,"")
         sheet.cells(rowsNum, 5) = IIF(col.Primary,"√","")
         sheet.cells(rowsNum, 6) = IIF(col.Primary,"√","")
         sheet.cells(rowsNum, 7) = IIF(col.Mandatory,"√","")
         sheet.cells(rowsNum, 8) = "无"
         sheet.cells(rowsNum, 9) = col.comment 
      next  

      '设置边框  
      DIM RanagBorder
      SET RanagBorder =sheet.Range(sheet.cells(rowsNum-colsNum,1),sheet.cells(rowsNum,9))
      RanagBorder.Borders.LineStyle = "1"
      'RaneBorderFun RanagBorder  
      
      rowsNum = rowsNum + 1  
      
   End If  
End Sub  

function IIF(flg,tstr,fstr)
   if flg then
      IIF= tstr
   else
      IIF= fstr
   end if
End function

 

上一篇:定义了重复的system.web.extensions/scripting/scriptResourceHandler怎么办


下一篇:typescript_运行后生成相应的js脚本设置_python_pandas多sheet页保存