我在行中有很多json数据,需要在Excel中从中提取某些数据,有没有办法做到这一点?我提供了一个典型单元的样本,为了简单起见,我如何从中提取“Lat”和“lng”值并将它们放在相邻的单元格中。所以让我们说json在单元格D2中,我需要E3中的'lat'和F3中的'Lng':
projectId:'5571511970726f3903000000',
lat:13.737738,
lng:100.566147,
destinations:[{"id":"57bc75550ce0fe28af001609","name":"BrownEyesRestaurant","category_name":"restaurant","category_class_name":"restaurants","lat":13.737875,"lng":100.566806,"travel_time":"lessthanaminutebyfoot","distance_human":"39m","distance_in_meters":39},{"id":"57bc75550ce0fe28af00160a","name":"HanaHana","category_name":"restaurant","category_class_name":"restaurants","lat":13.738215,"lng":100.566701,"travel_time":"1minutebyfoot","distance_human":"48m","distance_in_meters":48},{"id":"57bc75550ce0fe28af001602","name":"7-Eleven","category_name":"convenience_store","category_class_name":"shopping","lat":13.73763,"lng":100.566934,"travel_time":"1minutebyfoot","distance_human":"55m","distance_in_meters":55},{"id":"57bc75550ce0fe28af001636","name":"GoldenShrine","category_name":"pokestop","category_class_name":"pokemon_places","lat":13.737763,"lng":100.567128,"travel_time":"1minutebyfoot","distance_human":"74m","distance_in_meters":74},{"id":"57bc75550ce0fe28af00160d","name":"FatFishSeafoodBistro","category_name":"restaurant","category_class_name":"restaurants","lat":13.737128,"lng":100.567127,"travel_time":"2minutesbyfoot","distance_human":"130m","distance_in_meters":126},{"id":"57bc75550ce0fe28af001635","name":"NARZStoneBalls","category_name":"pokestop","category_class_name":"pokemon_places","lat":13.738174,"lng":100.56538,"travel_time":"2minutesbyfoot","distance_human":"140m","distance_in_meters":142},
screengrab上所需输出的示例:
答案 0 :(得分:1)
如果您不打算提取json,请尝试使用此代码。
Sub test()
Dim s As String
Dim vSplit
s = Range("d2")
vSplit = Split(s, ",")
Range("e2") = Val(Replace(vSplit(1), "lat:", ""))
Range("f2") = Val(Replace(vSplit(2), "lng:", ""))
End Sub
修改强>
Sub test()
Dim s As String
Dim vSplit
Dim vDB, vR()
Dim i As Long, n As Long
vDB = Range("d2", Range("d" & Rows.Count).End(xlUp))
n = UBound(vDB, 1)
ReDim vR(1 To n, 1 To 2)
For i = 1 To n
s = vDB(i, 1)
vSplit = Split(s, ",")
vR(i, 1) = Val(Replace(vSplit(1), "lat:", ""))
vR(i, 2) = Val(Replace(vSplit(2), "lng:", ""))
Next i
Range("e2").Resize(n, 2) = vR
End Sub