1.打开pd(我这里用的是pd15),新建一个物理模型(PhysicalDataModel),打开下面的菜单
输入脚本,更改脚本中所要求的部分,删除提示更改的语句
Option Explicit
Dim mdl ' the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then MsgBox "There is no Active Model" End If
Dim HaveExcel
Dim RQ
RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")
If RQ = vbYes Then
HaveExcel = True
' Open & Create Excel Document
x1.Workbooks(1).Worksheets("Sheet1").Activate
Dim x1 '
Set x1 = CreateObject("Excel.Application")
Else HaveExcel = False
x1.Workbooks.Open "D:/test.xlsx" --更改要导入的excel名称
End If
For rwIndex = 1 To 4 step 1 --更改这里循环的列数
a x1, mdl
sub a(x1, mdl)
dim rwIndex
dim colname
dim tableName
dim table
dim col
dim count 'on error Resume Next
If .Cells(rwIndex, 1).Value = "" Then
With x1.Workbooks(1).Worksheets("Sheet1")
'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表"
Exit For
table.Name = .Cells(rwIndex , 1).Value
End If
If .Cells(rwIndex, 3).Value = "" Then
set table = mdl.Tables.CreateNew
colName = .Cells(rwIndex, 1).Value
table.Code = .Cells(rwIndex , 2).Value
count = count + 1
Else
set col = table.Columns.CreateNew
col.Code = .Cells(rwIndex, 2).Value
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
col.Name = .Cells(rwIndex, 1).Value
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Comment = .Cells(rwIndex,4).Value
End sub
col.DataType = .Cells(rwIndex, 3).Value
End If
End With
Next
MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表"
Exit Sub
准备excel表,表格式为
准备就绪,run就行了