DB建模工具-Excel表结构导入PowerDesigner

Excel

上市公司年报 bd_quoted_company_annual_report
字段中文名 字段名 字段类型 注释 主键 默认值 字段名
对象ID object_id VARCHAR(100) 对象ID OBJECT_ID
证券代码 stock_code VARCHAR(40) 证券代码 Stock_CODE
证券简称 stock_name VARCHAR(40) 证券简称 Stock_NAME
行业 industry VARCHAR(40) 行业 industry
年份 year VARCHAR(10) 年份 year
季度 quarter VARCHAR(10) 年报:0,季报:3、6、9、12 quarter
报告期 report_period VARCHAR(10) 报告期 REPORT_PERIOD
公告标题 ann_title VARCHAR(100) 公告标题 ann_title
公告正文标题 ann_body_title VARCHAR(100) 公告正文标题 ann_body_title
公告url ann_url VARCHAR(1000) 公告url ann_url
公告日期 ann_dt VARCHAR(20) 公告日期 ANN_DT
官方pdf地址 official_pdf_url VARCHAR(1000) 官方pdf地址 official _pdf_url
官方pdf名 official_pdf_name VARCHAR(100) 官方pdf名 official _pdf_name

Excel宏定义

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 "C:\Users\hun.wong\Desktop\hm-bigdata-table1.xlsx" 
  x1.Workbooks(1).Worksheets("主营业务收入成本").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 1000 step 1   
    With x1.Workbooks(1).Worksheets("主营业务收入成本")
  'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表" 
   If .Cells(rwIndex, 1).Value = "" Then 
       rwIndex = rwIndex + 1
       IF .Cells(rwIndex, 1).Value = "" then
       Exit For 
       end if
   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 
        table.Comment = .Cells(rwIndex, 1).Value
        rwIndex  = rwIndex + 1
        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,4).Value  
    col.DataType = .Cells(rwIndex, 3).Value 
	If .Cells(rwIndex, 5).Value ="是" then
		col.Primary = true
	end if
	If .Cells(rwIndex, 6).Value <>"" then
		col.DefaultValue = .Cells(rwIndex, 6).Value
	end if
   End If 
  End With 
Next 
  
MsgBox "生成数据表结构共计" + CStr(count), vbOK + vbInformation, "表" 
x1.Workbooks.Close 
Exit Sub 
End sub

打开PowerDesigner,如下图执行脚本

posted @ 2021-04-26 10:12  叨叨勋  阅读(166)  评论(0编辑  收藏  举报