以为删除了,还是让我找到了个:
'开始
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
Else
HaveExcel = False
End If
' Open & Create Excel Document
Dim x1 '
Set x1 = CreateObject("Excel.Application")
x1.Workbooks.Open "D:workapprove杂项征信数据库字段整理征信数据库报文解析入库字段说明-前海征信.xlsx" '指定 excel文档路径
Dim sh1,iSheet
For iSheet=1 To x1.Workbooks(1).Sheets.Count
Set sh1 = x1.Workbooks(1).Sheets(iSheet)
sh1.Activate '指定要打开的sheet名称
'a x1, mdl
'sub a(x1, mdl)
dim rwIndex
dim tableName
dim colname
dim table
dim col
dim count
on error Resume Next
set table = mdl.Tables.CreateNew '创建一个 表实体
table.Name = sh1.Name '指定 表名,如果在 Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
table.Code = sh1.Cells(1, 1) '指定 表名
count = count + 1
For rwIndex = 2 To 100 '指定要遍历的 Excel行标 由于第1行是 表头, 从第2行开始
With sh1
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End If
set col = table.Columns.CreateNew '创建一列/字段
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
col.Name = .Cells(rwIndex, 2).Value
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Code = .Cells(rwIndex, 1).Value '指定列名
col.DataType = .Cells(rwIndex, 3).Value '指定列数据类型
col.Comment = col.Name+.Cells(rwIndex, 4).Value '指定列说明
If .Cells(rwIndex, 5).Value = "否" Then
col.Mandatory = true '指定列是否可空 true 为不可空
End If
If rwIndex = 2 Then
col.Primary = true '指定主键
End If
End With
Next
Next 'end For iSheet
MsgBox "生成数据 表结构共计 " + CStr(count), vbOK + vbInformation, " 表"+table.Code
'Exit Sub
'End sub
操作col.length
'开始
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
Else
HaveExcel = False
End If
' Open & Create Excel Document
Dim x1 '
Set x1 = CreateObject("Excel.Application")
x1.Workbooks.Open "Z:Documentspowerdesignerexcelsc-propowerdesigner_sc1.xlsx" '指定 excel文档路径
Dim sh1,iSheet
For iSheet=2 To x1.Workbooks(1).Sheets.Count '跳过第一页,从第二页开始
Set sh1 = x1.Workbooks(1).Sheets(iSheet)
sh1.Activate '指定要打开的sheet名称
'a x1, mdl
'sub a(x1, mdl)
dim rwIndex
dim tableName
dim colname
dim table
dim col
dim count
on error Resume Next
set table = mdl.Tables.CreateNew '创建一个 表实体
table.Name = sh1.Name 'sh1.Name '指定 表名,如果在 Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
'MsgBox sh1.Name, vbOK + vbInformation, "列"
table.Code = table.Name '指定 表名
count = count + 1
For rwIndex = 6 To 100 '指定要遍历的 Excel行标 由于第1行是 表头, 从第6行开始
With sh1
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End If
set col = table.Columns.CreateNew '创建一列/字段
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
col.Name = .Cells(rwIndex, 2).Value
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Code = .Cells(rwIndex, 3).Value '指定列名
'MsgBox col.DataType, vbOK + vbInformation, "列"
If .Cells(rwIndex, 5).Value <> "" Then
col.DataType = .Cells(rwIndex, 4).Value & "("&.Cells(rwIndex, 5).Value &")"'指定列长度
else
col.DataType = .Cells(rwIndex, 4).Value '指定列数据类型
End If
col.Comment = .Cells(rwIndex, 9).Value '指定列说明
If .Cells(rwIndex, 7).Value = "否" Then
col.Mandatory = true '指定列是否可空 true 为不可空
End If
If rwIndex = 6 Then
col.Primary = true '指定主键
End If
End With
Next
Next 'end For iSheet
MsgBox "生成数据 表结构共计 " + CStr(count), vbOK + vbInformation, " 表"+table.Code
'Exit Sub
'End sub
加了comment 的版本:
'开始
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
Else
HaveExcel = False
End If
' Open & Create Excel Document
Dim x1 '
Set x1 = CreateObject("Excel.Application")
x1.Workbooks.Open "Z:Documentspowerdesignerexcelsc-propowerdesigner_sc1.xlsx" '指定 excel文档路径
Dim sh1,iSheet
For iSheet=2 To x1.Workbooks(1).Sheets.Count '跳过第一页,从第二页开始
Set sh1 = x1.Workbooks(1).Sheets(iSheet)
sh1.Activate '指定要打开的sheet名称
'a x1, mdl
'sub a(x1, mdl)
dim rwIndex
dim tableName
dim colname
dim table
dim col
dim count
on error Resume Next
set table = mdl.Tables.CreateNew '创建一个 表实体
table.Name = sh1.Cells(3, 2).Value 'sh1.Name '指定 表名,如果在 Excel文档里有,也可以 .Cells(rwIndex, 3).Value 这样指定
'MsgBox sh1.Name, vbOK + vbInformation, "列"
table.Code = sh1.Name '指定 表名
table.Comment = table.Name
count = count + 1
For rwIndex = 6 To 100 '指定要遍历的 Excel行标 由于第1行是 表头, 从第6行开始
With sh1
If .Cells(rwIndex, 1).Value = "" Then
Exit For
End If
set col = table.Columns.CreateNew '创建一列/字段
'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"
col.Name = .Cells(rwIndex, 2).Value
'MsgBox col.Name, vbOK + vbInformation, "列"
col.Code = .Cells(rwIndex, 3).Value '指定列名
'MsgBox col.DataType, vbOK + vbInformation, "列"
If .Cells(rwIndex, 5).Value <> "" Then
col.DataType = .Cells(rwIndex, 4).Value & "("&.Cells(rwIndex, 5).Value &")"'指定列长度
else
col.DataType = .Cells(rwIndex, 4).Value '指定列数据类型
End If
col.Comment = .Cells(rwIndex, 9).Value '指定列说明
If .Cells(rwIndex, 7).Value = "否" Then
col.Mandatory = true '指定列是否可空 true 为不可空
End If
If rwIndex = 6 Then
col.Primary = true '指定主键
End If
End With
Next
Next 'end For iSheet
MsgBox "生成数据 表结构共计 " + CStr(count), vbOK + vbInformation, " 表"+table.Code
'Exit Sub
'End sub