Excel读入通达信1分钟数据
通达信1分钟线*.lc1文件格式:
每32个字节为一个1分钟数据,每字段内低字节在前
00 ~ 01 字节:日期,2字节整型,设其值为date,则日期计算方法为:
year=int(date/2048)+2036;
Month-day=date - Int(date / 2048) * 2048;
02 ~ 03 字节: 从0点开始至目前的分钟数,2字节整型,
设其值为time,则时间计算方法为:hour=int(time/60),min=time-int(time/60)*60
04 ~ 07 字节:开盘价,4字节浮点型
08 ~ 11 字节:最高价,4字节浮点型
12 ~ 15 字节:最低价,4字节浮点型
16 ~ 19 字节:收盘价,4字节浮点型
20 ~ 23 字节:成交额(元),4字节浮点型
24 ~ 27 字节:成交量(股),4字节长整型
28 ~ 31 字节:(保留),4字节长整型
Excel VBA宏文件如下:
Type MyType
tdxD As Integer '日期
tdxT As Integer '时间
tdxO As Single '开盘
tdxH As Single '最高
tdxL As Single '最低
tdxC As Single '收盘
tdxJ As Single '成交量
tdxN As Long '成交额
tdxX As Long '保留
End Type
Sub 箭头上2_Click()
Filename = ThisWorkbook.Path & "\sh688073.lc1"
'Filename = ThisWorkbook.Path & "\sh600330.lc1"
Dim b As MyType
Open Filename For Binary As #1
i = 2
Do While Not EOF(1)
Get #1, , b
Cells(i, 1) = b.tdxD
Cells(i, 2) = b.tdxT
Cells(i, 3) = b.tdxO
Cells(i, 4) = b.tdxH
Cells(i, 5) = b.tdxL
Cells(i, 6) = b.tdxC
Cells(i, 7) = Round(b.tdxJ / 100, 0)
Cells(i, 8) = b.tdxN
Cells(i, 9) = b.tdxX
Cells(i, 10) = Int(b.tdxD / 2048) + 2036 '年
Cells(i, 11) = b.tdxD - Int(b.tdxD / 2048) * 2048 '月日
Cells(i, 12) = Int(b.tdxT / 60) '时
Cells(i, 13) = b.tdxT - Int(b.tdxT / 60) * 60 '分
i = i + 1
Loop
Close #1
End Sub