繁体   English   中英

从众多文本文件中提取多行数据,并关联到Excel中

[英]Extract multiple lines of data from numerous text files and correlate into Excel

关于如何从以下位置修改脚本的任何建议:

从众多文本文件中提取一行数据并导入Excel

要生成一个Excel工作表,该工作表的文件名位于一列(.ini文件的文件名),第二列中的纬度,第三列中的经度? 我也有一堆.ini文件,其中包含.jpg的相机参数,但需要提取Name,Lat和Long进行进一步处理。

这是.ini文件的示例:


[top_left]
lng =  -80.5251854921
lat =   46.6276919869

[top_right]
lng =  -80.5307483620
lat =   46.6297628116

[bottom_left]
lng =  -80.5229096407
lat =   46.6307857000

[bottom_right]
lng =  -80.5281836560
lat =   46.6327636148

[center]
lng =  -80.5267096969
lat =   46.6302821844

[origin]
Xs =       319.50000
Ys =       239.50000

[map]
A00 =         0.0008197901
A01 =        -0.0085907931
A02 =       -80.5267154968
A10 =        -0.0004764527
A11 =         0.0049839176
A12 =        46.6302857603
A20 =        -0.0000102856
A21 =         0.0001067452
A22 =         1.0000000000

[frameTimestamp]
frameTs = 0

我尝试使用某些代码从一个文件夹中的多个文本文件提取数据到excel工作表中 ,但收效甚微。

这应该做您想要的-但没有错误处理-它假定每个文件都按照示例中的显示进行布局。 另外,我假设任何纬度/经度对都可以,并且您只想要其中一个。 因此,我提取了与“ top_left”关联的那个。 同样,所有.ini文件都位于C:Temp \\ Test目录中,并假定您希望将数据追加到ActiveSheet的最后一行之后:

Option Explicit

Sub ExtractLatLng()
    Dim MyFolder As String, MyFile As String, textline As String
    Dim r As Integer, pos As Integer

    MyFolder = "C:\Temp\Test\"
    MyFile = dir(MyFolder & "*.ini")

    r = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row + 1
    Do While MyFile <> ""
        Open (MyFolder & MyFile) For Input As #1
        Do Until EOF(1)
          Line Input #1, textline
          pos = InStr(textline, "[top_left]")
          If pos = 1 Then
             ActiveSheet.Cells(r, "A").Value = MyFile
             Line Input #1, textline
             pos = InStr(textline, "=")
             ActiveSheet.Cells(r, "C").Value = Mid(textline, pos + 1)
             Line Input #1, textline
             pos = InStr(textline, "=")
             ActiveSheet.Cells(r, "B").Value = Mid(textline, pos + 1)
             r = r + 1
             Exit Do
          End If
        Loop
        Close #1
        MyFile = dir()
    Loop 
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM