pdm2excel
1
'
******************************************************************************
2 ' * File: pdm2excel.txt
3 ' * Title: pdm export to excel
4 ' * Purpose: To export the tables and columns to Excel
5 ' * Model: Physical Data Model
6 ' * Objects: Table, Column, View
7 ' * Author: ziyan
8 ' * Created: 2012-05-03
9 ' *Modifier: Hui Wanpeng 2014/07/04
10 ' * Version: 1.0
11 ' ******************************************************************************
12 Option Explicit
13 Dim rowsNum
14 rowsNum = 0
15
16 ' -----------------------------------------------------------------------------
17 ' Main function
18 ' -----------------------------------------------------------------------------
19 ' Get the current active model
20
21 Dim Model
22 Set Model = ActiveModel
23 If (Model Is Nothing) Or ( Not Model.IsKindOf(PdPDM.cls_Model)) Then
24 MsgBox "The current model is not an PDM model."
25 Else
26 ' Get the tables collection
27 ' 创建EXCEL APP
28 Dim beginrow
29 Dim EXCEL, SHEET
30 set EXCEL = CREATEOBJECT("Excel.Application")
31 EXCEL.workbooks.add(-4167) ' 添加工作表
32 EXCEL.workbooks(1).sheets(1).name ="test"
33 set sheet = EXCEL.workbooks(1).sheets("test")
34
35 ShowProperties Model, SHEET
36 EXCEL.visible = true
37
38 ' 设置列宽和自动换行
39 sheet.Columns(1).ColumnWidth = 20
40 sheet.Columns(2).ColumnWidth = 40
41 sheet.Columns(4).ColumnWidth = 20
42 sheet.Columns(5).ColumnWidth = 20
43 sheet.Columns(6).ColumnWidth = 15
44 sheet.Columns(1).WrapText = true
45 sheet.Columns(2).WrapText = true
46 sheet.Columns(4).WrapText = true
47 End If
48
49 ' -----------------------------------------------------------------------------
50 ' Show properties of tables
51 ' -----------------------------------------------------------------------------
52 Sub ShowProperties(mdl, sheet)
53 ' Show tables of the current model/package
54 rowsNum=0
55 beginrow = rowsNum+1
56
57 ' For each table
58 output "begin"
59
60 Dim tab
61 For Each tab In mdl.tables
62 ShowTable tab,sheet
63 Next
64
65 if mdl.tables.count > 0 then
66 sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group
67 end if
68 output "end"
69 End Sub
70
71 ' -----------------------------------------------------------------------------
72 ' Show table properties
73 ' -----------------------------------------------------------------------------
74 Sub ShowTable(tab, sheet)
75 If IsObject(tab) Then
76 Dim rangFlag
77 rowsNum = rowsNum + 1
78
79 ' Show properties
80 Output "================================"
81 sheet.cells(rowsNum, 1) = "实体名"
82 sheet.cells(rowsNum, 2) =tab.name
83 sheet.cells(rowsNum, 3) = ""
84 sheet.cells(rowsNum, 4) = "表名"
85 sheet.cells(rowsNum, 5) = tab.code
86 sheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).Merge
87 rowsNum = rowsNum + 1
88 sheet.cells(rowsNum, 1) = "属性名"
89 sheet.cells(rowsNum, 2) = "说明"
90 sheet.cells(rowsNum, 3) = ""
91 sheet.cells(rowsNum, 4) = "字段中文名"
92 sheet.cells(rowsNum, 5) = "字段名"
93 sheet.cells(rowsNum, 6) = "字段类型"
94
95 ' 设置边框
96 sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Borders.LineStyle = "1"
97 sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Interior.ColorIndex = 20
98 sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Borders.LineStyle = "1"
99 sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Interior.ColorIndex = 20
100
101 Dim col ' running column
102 Dim colsNum
103 colsNum = 0
104 for each col in tab.columns
105 rowsNum = rowsNum + 1
106 colsNum = colsNum + 1
107 sheet.cells(rowsNum, 1) = col.name
108 sheet.cells(rowsNum, 2) = col.comment
109 sheet.cells(rowsNum, 3) = ""
110 ' sheet.cells(rowsNum, 4) = col.name
111 sheet.cells(rowsNum, 4) = col.comment
112 sheet.cells(rowsNum, 5) = col.code
113 sheet.cells(rowsNum, 6) = col.datatype
114 next
115 sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,2)).Borders.LineStyle = "2"
116 sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,6)).Borders.LineStyle = "2"
117 rowsNum = rowsNum + 1
118 Output "FullDescription: " + tab.Name
119 End If
120 End Sub
121
2 ' * File: pdm2excel.txt
3 ' * Title: pdm export to excel
4 ' * Purpose: To export the tables and columns to Excel
5 ' * Model: Physical Data Model
6 ' * Objects: Table, Column, View
7 ' * Author: ziyan
8 ' * Created: 2012-05-03
9 ' *Modifier: Hui Wanpeng 2014/07/04
10 ' * Version: 1.0
11 ' ******************************************************************************
12 Option Explicit
13 Dim rowsNum
14 rowsNum = 0
15
16 ' -----------------------------------------------------------------------------
17 ' Main function
18 ' -----------------------------------------------------------------------------
19 ' Get the current active model
20
21 Dim Model
22 Set Model = ActiveModel
23 If (Model Is Nothing) Or ( Not Model.IsKindOf(PdPDM.cls_Model)) Then
24 MsgBox "The current model is not an PDM model."
25 Else
26 ' Get the tables collection
27 ' 创建EXCEL APP
28 Dim beginrow
29 Dim EXCEL, SHEET
30 set EXCEL = CREATEOBJECT("Excel.Application")
31 EXCEL.workbooks.add(-4167) ' 添加工作表
32 EXCEL.workbooks(1).sheets(1).name ="test"
33 set sheet = EXCEL.workbooks(1).sheets("test")
34
35 ShowProperties Model, SHEET
36 EXCEL.visible = true
37
38 ' 设置列宽和自动换行
39 sheet.Columns(1).ColumnWidth = 20
40 sheet.Columns(2).ColumnWidth = 40
41 sheet.Columns(4).ColumnWidth = 20
42 sheet.Columns(5).ColumnWidth = 20
43 sheet.Columns(6).ColumnWidth = 15
44 sheet.Columns(1).WrapText = true
45 sheet.Columns(2).WrapText = true
46 sheet.Columns(4).WrapText = true
47 End If
48
49 ' -----------------------------------------------------------------------------
50 ' Show properties of tables
51 ' -----------------------------------------------------------------------------
52 Sub ShowProperties(mdl, sheet)
53 ' Show tables of the current model/package
54 rowsNum=0
55 beginrow = rowsNum+1
56
57 ' For each table
58 output "begin"
59
60 Dim tab
61 For Each tab In mdl.tables
62 ShowTable tab,sheet
63 Next
64
65 if mdl.tables.count > 0 then
66 sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group
67 end if
68 output "end"
69 End Sub
70
71 ' -----------------------------------------------------------------------------
72 ' Show table properties
73 ' -----------------------------------------------------------------------------
74 Sub ShowTable(tab, sheet)
75 If IsObject(tab) Then
76 Dim rangFlag
77 rowsNum = rowsNum + 1
78
79 ' Show properties
80 Output "================================"
81 sheet.cells(rowsNum, 1) = "实体名"
82 sheet.cells(rowsNum, 2) =tab.name
83 sheet.cells(rowsNum, 3) = ""
84 sheet.cells(rowsNum, 4) = "表名"
85 sheet.cells(rowsNum, 5) = tab.code
86 sheet.Range(sheet.cells(rowsNum, 5),sheet.cells(rowsNum, 6)).Merge
87 rowsNum = rowsNum + 1
88 sheet.cells(rowsNum, 1) = "属性名"
89 sheet.cells(rowsNum, 2) = "说明"
90 sheet.cells(rowsNum, 3) = ""
91 sheet.cells(rowsNum, 4) = "字段中文名"
92 sheet.cells(rowsNum, 5) = "字段名"
93 sheet.cells(rowsNum, 6) = "字段类型"
94
95 ' 设置边框
96 sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Borders.LineStyle = "1"
97 sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 2)).Interior.ColorIndex = 20
98 sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Borders.LineStyle = "1"
99 sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 6)).Interior.ColorIndex = 20
100
101 Dim col ' running column
102 Dim colsNum
103 colsNum = 0
104 for each col in tab.columns
105 rowsNum = rowsNum + 1
106 colsNum = colsNum + 1
107 sheet.cells(rowsNum, 1) = col.name
108 sheet.cells(rowsNum, 2) = col.comment
109 sheet.cells(rowsNum, 3) = ""
110 ' sheet.cells(rowsNum, 4) = col.name
111 sheet.cells(rowsNum, 4) = col.comment
112 sheet.cells(rowsNum, 5) = col.code
113 sheet.cells(rowsNum, 6) = col.datatype
114 next
115 sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,2)).Borders.LineStyle = "2"
116 sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,6)).Borders.LineStyle = "2"
117 rowsNum = rowsNum + 1
118 Output "FullDescription: " + tab.Name
119 End If
120 End Sub
121