|
- 'WPS 要安装 AccessDatabaseEngine.exe 下载地址 https://www.onlinedown.net/soft/1180584.htm
-
- Sub test1()
- Dim ar(1 To 200, 1 To 1000), br, Conn As Object, Flag As Boolean
- Dim strPath As String, strFile As String, SQL As String
- Dim i As Long, j As Long, k As Long
- Dim rowSize As Long, colSize As Long
-
- Cells.ClearContents
- Application.ScreenUpdating = False
-
- strPath = ThisWorkbook.Path & "\"
- Set Conn = CreateObject("ADODB.Connection")
- 'Conn.Open "Provider = Microsoft.ACE.OLEDB.12.0;Extended Properties='text;HDR=NO;FMT=Delimited;CharacterSet=65001';Data Source=" & strPath
- With Conn
- If Application.Version < 12 Or InStr(Application.Path, "WPS") > 0 Then
- .Provider = "Microsoft.Jet.OLEDB.4.0"
- Else
- .Provider = "Microsoft.ACE.OLEDB.12.0"
- End If
- .ConnectionString = "Data Source=" & strPath & ";Extended Properties='text;HDR=NO;FMT=CSVDelimited;CharacterSet=65001';"
- .Open
- End With
-
- rowSize = 1
- ar(rowSize, 1) = "LOG名称"
- ar(rowSize, 2) = "坐标"
- For j = 3 To UBound(ar, 2)
- ar(rowSize, j) = "R" & j - 2
- Next
-
- strFile = Dir(strPath & "*.txt")
-
- Do
- SQL = "SELECT * FROM [" & strFile & "] WHERE F1 LIKE '%,x=%BIN=%y=%' OR F1 LIKE '%R%ohm'"
- br = Conn.Execute(SQL).GetRows
- For j = 0 To UBound(br, 2)
- If br(0, j) Like "*,x=*BIN=*y=*" Then
- Flag = False
- rowSize = rowSize + 1
- ar(rowSize, 1) = Split(strFile, ".txt")(0)
- ar(rowSize, 2) = Mid(br(0, j), InStr(br(0, j), ",") + 1)
- End If
- If br(0, j) Like "R10X=*ohm" Then
- Flag = True
- j = j + 1
- k = 2
- End If
- If Flag Then
- If br(0, j) Like "R=*ohm" Then
- k = k + 1
- ar(rowSize, k) = Split(Split(br(0, j), "=")(1), Chr(32))(0)
- End If
- If k > colSize Then colSize = k
- End If
- Next
- strFile = Dir
- Loop While Len(strFile)
-
- Range("A1").Resize(rowSize, colSize) = ar
-
- Conn.Close
- Set Conn = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码
测试.zip
(29.49 KB, 下载次数: 3)
|
|