编写测试EXCEL,格式如下
打开PowerDesigner,创建物理模型(Physical Data Model)
在PowerDesigner菜单栏中,依次点击“Tools ->Excute Commands->Edit/Run Script…”
修改脚本,指定excel所在路径及文件名
Option ExplicitDim mdl \' the current modelSet mdl = ActiveModelIf (mdl Is Nothing) ThenMsgBox \"There is no Active Model\"End IfDim HaveExcelDim RQDim x1sApp,xlsWorkBook,xlsSheetRQ = vbYes \'MsgBox(\"Is Excel Installed on your machine ?\", vbYesNo + vbInformation, \"Confirmation\")If RQ = vbYes ThenHaveExcel = True\' Open & Create Excel DocumentSet x1sApp = CreateObject(\"Excel.Application\")set xlsWorkBook = x1sApp.Workbooks.Open(\"E:\\test.xlsx\") \'指定excel文档路径set xlsSheet = x1sApp.Workbooks(1).Worksheets(\"Sheet1\") \'指定要打开的sheet名称ElseHaveExcel = FalseEnd Ifa x1sApp, mdl,x1sApp,xlsWorkBook,xlsSheetsub a(x1, mdl,x1sApp,xlsWorkBook,xlsSheet)dim rwIndexdim tableNamedim colnamedim tabledim coldim countdim rowCountrowCount = xlsSheet.usedRange.Rows.Counton error Resume NextFor rwIndex = 2 To rowCount \'指定要遍历的Excel行标 由于第1行是表头,从第2行开始With xlsSheetIf .Cells(rwIndex, 2).Value = \"\" Then \'如果遍历到第二列为空,则退出Exit ForEnd IfIf .Cells(rwIndex, 3).Value = \"\" Then \'如果遍历到第三列为空,则此行为表名set table = mdl.Tables.CreateNew \'创建表table.Name = .Cells(rwIndex , 1).Value \'指定表名,第二列的值table.Code = .Cells(rwIndex , 2).Valuetable.Comment = .Cells(rwIndex , 1).Value \'指定表注释,第一列的值count = count + 1Elseset col = table.Columns.CreateNew \'创建一列/字段\'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, \"列\"col.Name = .Cells(rwIndex, 1).Value \'指定列名\'MsgBox col.Name, vbOK + vbInformation, \"列\"col.Code = .Cells(rwIndex, 2).Value \'指定列名col.DataType = .Cells(rwIndex, 3).Value \'指定列数据类型\'MsgBox col.DataType, vbOK + vbInformation, \"列类型\"col.Comment = .Cells(rwIndex, 6).Value \'指定列说明if .Cells(rwIndex, 4).Value = \"Primary Key\" Thencol.Primary = trueEnd IfIf.Cells(rwIndex, 5).Value = \"NOT NULL\" Thencol.Mandatory =trueEnd IfEnd IfEnd WithNextMsgBox \"生成数据表结构共计 \" + CStr(count), vbOK + vbInformation, \"表\"xlsWorkBook.Closex1sApp.Quitset x1sApp = nothingset xlsWorkBook = nothingExit SubEnd sub