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 Dim x1 ' Set x1 = CreateObject("Excel.Application") x1.Workbooks.Open "D:/Test.xlsx" x1.Workbooks(1).Worksheets("Sheet1").Activate Else HaveExcel = False End If a x1, mdl sub a(x1,mdl) dim rwIndex dim tableName dim colname dim table dim col dim count 'on error Resume Next For rwIndex = 1 To 50 step 1 With x1.Workbooks(1).Worksheets("Sheet1") 'MsgBox "生成數據表結構共計1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表" If .Cells(rwIndex, 1).Value = "" Then Exit For End If If .Cells(rwIndex, 3).Value = "" Then set table = mdl.Tables.CreateNew table.Name = .Cells(rwIndex , 1).Value table.Code = .Cells(rwIndex , 2).Value count = count + 1 Else colName = .Cells(rwIndex, 1).Value set 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.Comment = .Cells(rwIndex,1).Value col.DataType = .Cells(rwIndex, 3).Value End If End With Next MsgBox "生成數據表結構共計" + CStr(count), vbOK + vbInformation, "表" Exit Sub End sub
代碼說明:數據庫
1.) For rwIndex = 1 To 50 step 1 此處是定義生成的行數,即字段數量50,能夠修改此數ide
2.) x1.Workbooks.Open "D:/Test.xlsx" 此處是 excel 數據庫表結構存入的位置,能夠自定義位置和名稱spa
3)Test.xlsx 中 的 「應申報統計」數據庫表 結構以下:代理
應申報統計(表名name) | SB_YSBTJ(表名code) | |
會計制度(準則)代碼 | KJZDZZ_DM | CHAR(3) |
是否催報及監控未申報 | SFCBJJKWSB | CHAR(1) |
做廢日期 | ZFRQ_1 | DATE |
徵收方式代碼 | ZSFS_DM | CHAR(3) |
納稅期限代碼 | NSQX_DM | CHAR(2) |
稅款所屬期止 | SKSSQZ | DATE |
稅款所屬期起 | SKSSQQ | DATE |
月份 | YF | CHAR(2) |
年度 | ND | VARCHAR2(10) |
徵收品目代碼 | ZSPM_DM | CHAR(9) |
徵收項目代碼 | ZSXM_DM | VARCHAR2(5) |
登記序號 | DJXH | NUMBER(20) |
納稅申報日期 | NSSBRQ | DATE |
原申報期限 | YSBQX | DATE |
申報期限 | SBQX | DATE |
數據來源標誌 | SJLYBZ | CHAR(1) |
徵收代理方式代碼 | ZSDLFS_DM | CHAR(1) |
行業代碼 | HY_DM | VARCHAR2(4) |
修改日期 | XGRQ | DATE |
修改人代碼 | XGR_DM | CHAR(11) |
錄入日期 | LRRQ | DATE |
申報方式代碼 | SBFS_DM | CHAR(2) |
數據歸屬地區 | SJGSDQ | CHAR(11) |
錄入人代碼 | LRR_DM | CHAR(11) |
主管稅務所(科、分局)代碼 | ZGSWSKFJ_DM | CHAR(11) |
主管稅務局代碼 | ZGSWJ_DM | CHAR(11) |
稅收管理員代碼 | SSGLY_DM | CHAR(11) |
做廢人代碼 | ZFR_DM | CHAR(11) |
做廢標誌 | ZFBZ_1 | CHAR(1) |
應申報統計UUID | YSBTJUUID | VARCHAR2(32) |
數據同步時間 | SJTB_SJ | TIMESTAMP |
稅源編號 | SYBH_1 | VARCHAR2(40) |
將上面的代碼保存爲vbscript保存至 C:\Program Files (x86)\Sybase\PowerDesigner 15\VB Scripts 中,命名爲:generate_table_structure_for_excel.vbsexcel
而後在PD菜單 Tool -> Execute Commands-> Edit/Run Script 選擇上面所保存的vb scriptcode