我正在使用Hanna传感器仪器来记录一些数据,这些数据来自具有十六进制代码的.log文件。 然后我使用Hanna软件(附带仪器)将该数据转换为excel格式(数字和字符及特殊字符)。 我想知道它是如何做到的,如果可能的话,在没有软件的情况下自己做?
该文件如下所示,其扩展名为.log
4d65 7465 720a 3230 3137 3039 3139 0000
c1fb 5321 ffff 01fc 1fc8 ffff f4ff f92d
0dc3 58ff 4a00 0000 0000 735a 0081 6101
a242 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 003d 3950 82cc
0940 08b4 3088 c2fb 5321 ffff 01fc 1fc8
ffff f4ff 0b2e 0dae 58ff 4a00 0000 0000
a85a 00a8 6101 1143 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
.
.
.
continued
答案 0 :(得分:1)
尝试类似:
Sub JustOneFile()
Dim s As String, i As Long
i = 1
Close #1
Open "C:\TestFolder\james.log" For Input As #1
Do Until EOF(1)
Line Input #1, s
Cells(i, 1) = s
i = i + 1
Loop
Close #1
Columns("A:A").TextToColumns Destination:=Range("B1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), Array(4, 2), Array(9, 2), Array(14, 2), Array(19, 2), _
Array(24, 2), Array(29, 2), Array(34, 2)), TrailingMinusNumbers:=True
End Sub
答案 1 :(得分:0)
该过程涉及导入.LOG文件,然后循环遍历所有单元格并单独转换它们或将所有数据块存储到变量数组中,转换它们并将转换后的值返回到工作表。建议采用后一种转换方法。
Option Explicit
Sub wqewqw()
Dim hxwb As Workbook
Dim i As Long, j As Long, vals As Variant
Workbooks.OpenText Filename:="%USERPROFILE%\Documents\hex_2_excel.log", _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, TrailingMinusNumbers:=True, _
FieldInfo:=Array(Array(0, 2), Array(4, 2), Array(9, 2), Array(14, 2), _
Array(19, 2), Array(24, 2), Array(29, 2), Array(34, 2))
With ActiveWorkbook
With .Worksheets(1)
vals = .Cells(1, "A").CurrentRegion.Cells
For i = LBound(vals, 1) To UBound(vals, 1)
For j = LBound(vals, 2) To UBound(vals, 2)
vals(i, j) = Application.Hex2Dec(vals(i, j))
Next j
Next i
With .Cells(1, "A").Resize(UBound(vals, 1), UBound(vals, 2))
.NumberFormat = "General"
.Value = vals
End With
End With
End With
End Sub