利用excel生成pdm表结构

来源:互联网 发布:数字化转型 人工智能 编辑:程序博客网 时间:2024/05/09 20:26

第一步:整理Excel表结构(放到指定位置)



第二步:利用脚本生成pdm


脚本如下:

Option ExplicitDim mdl ' the current modelSet mdl = ActiveModelIf (mdl Is Nothing) Then   MsgBox "There is no Active Model"End IfDim HaveExcelDim RQRQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")If RQ = vbYes Then   HaveExcel = True   'Open & Create Excel Document   Dim x1     Set x1 = CreateObject("Excel.Application")   x1.Application.Visible = True   x1.Workbooks.Open "C:\jsxm.xlsx"'excel所在位置   x1.Workbooks(1).Worksheets("Sheet1").Activate'活动的sheetElse   HaveExcel = FalseEnd Ifa x1, mdlsub a(x1, mdl)dim rwIndexdim tableNamedim colnamedim tabledim coldim countdim  shtIdxfor shtIdx=1 to x1.Workbooks(1).Worksheets.Counton error Resume NextWith x1.Workbooks(1).Worksheets(shtIdx)If .Cells(1, 1).Value = "if_t_buildProject" Then'判断表count = count + 1               set table = mdl.Tables.CreateNewtable.Code = .Cells(1, 1).Value'表编码(对应excel的位置)table.Name = .Cells(1, 2).Value'表名table.Comment = .Cells(1, 3).Value'描述For rwIndex = 3 To 255'从第三列开始    If .Cells(rwIndex, 3).Value <> "" Then'类型不为空的set col = table.Columns.CreateNewcol.Name = .Cells(rwIndex, 1).Value'字段名col.Code = .Cells(rwIndex, 2).Value'字段编码col.Comment = .Cells(rwIndex, 8).Value'字段描述所在列col.DataType =  .Cells(rwIndex, 3).Value'数据类型                                 End If      Next    End If  End WithNextx1.Application.QuitSet x1=NothingMsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表"End sub


资源地址


0 0
原创粉丝点击