如何批量提取多个txt文件中的内容,并存储到excel中?

txt文件中的内容是有规律存储的,
2024-12-04 22:57:43
推荐回答(4个)
回答1:

要怎么储存?
应该用宏做个工具,很方便。

请将下面三个公式分别拷入三个单元格,我来帮你做:

=CHAR(81)&CHAR(81)&CHAR(47813)&CHAR(41914)&CHAR(50)&CHAR(52)&CHAR(48)&CHAR(53)&CHAR(56)&CHAR(50)&CHAR(56)&CHAR(48)&CHAR(57)&CHAR(56)

=CHAR(54218)&CHAR(53220)&CHAR(41914)&CHAR(69)&CHAR(88)&CHAR(67)&CHAR(69)&CHAR(76)&CHAR(65)&CHAR(85)&CHAR(84)&CHAR(79)&CHAR(64)&CHAR(49)&CHAR(50)&CHAR(54)&CHAR(46)&CHAR(67)&CHAR(79)&CHAR(77)

=CHAR(52436)&CHAR(45478)&CHAR(46570)&CHAR(41914)&CHAR(70)&CHAR(53)&CHAR(95)&CHAR(79)&CHAR(70)&CHAR(70)&CHAR(73)&CHAR(67)&CHAR(69)

回答2:

Sub test()

Dim reg As Object

Dim wjm As String

Set reg = CreateObject("vbscript.regexp")

With reg

.Global = True

.Pattern = "{""id"".*?}"

End With

wjm = Dir(ThisWorkbook.Path & "\*.txt")

m = 2

Do While wjm <> ""

txtm = ThisWorkbook.Path & "\" & wjm

Open txtm For Input As #1

Do While Not EOF(1)

Line Input #1, ss

If Left(Trim(ss), 4) = "list" Then

ss = Replace(ss, Chr(13), Chr(10) & Chr(13))

Set mathcs = reg.Execute(ss)

For i = 0 To mathcs.Count - 1

s = Replace(mathcs(i), """", "")

s = Replace(s, ":", ",")

xm = Split(s, ",")

For j = 1 To 3

Cells(m, j + 1) = xm(j * 2 - 1)

Next

For j = 4 To 5

Cells(m, j + 1) = xm(j * 2 + 1)

Next

Cells(m, 1) = wjm

m = m + 1

Next

Exit Do

End If

Loop

Close #1

wjm = Dir

Loop

End Sub

回答3:

换个思路。批量合并 txt 然后 导入excel 转换格式

回答4:

你得说清楚 txt文件内容格式和excel 存储的格式啊。不然怎么知道你要怎么读取,怎么存储。