Excel – 如何根据同一文本中的条件提取文本中的文本

一直在努力工作,但没有成功。 我正在尝试从Json文件中提取已翻译的数据,并提取不同列中翻译的不同列。 重要的是,数据并不总是具有相同的顺序。

json看起来像这样:

{“en”:“life”,“nl-BE”:“leven”,“de-DE”:“Leben”,“fr-BE”:“la vie”}

在Excel中看到我想实现的例子。 Excel示例

Column A Column B Column C Column D Column E Json "en" "nl-BE" "de-DE" "fr-BE" {"en":"life","nl-BE":"leven","de-DE":"Leben","fr-BE":"la vie"} life leven Leben la vie {"nl-BE":"Kinderen","de-DE":"Kinder","en":"Children","fr-BE":"Enfants"} Children Kinderen Kinder Enfants 

提前致谢。

使用这个公式:

 =SUBSTITUTE(SUBSTITUTE(TRIM(MID(SUBSTITUTE(SUBSTITUTE($A2,":",REPT(" ",99)),",",REPT(" ",99)),FIND(B$1,SUBSTITUTE(SUBSTITUTE($A2,":",REPT(" ",99)),",",REPT(" ",99)))+99,99)),"""",""),"}","") 

把它放在B2上复制。

在这里输入图像说明

除了@ScottCraner的优秀答案,你可以在VBA中编写一个UDF。 在一个标准的代码模块中,

 Function JsonExtractor(json As String, key As String) As String Dim data As String Dim items As Variant Dim item As Variant data = Trim(json) data = Mid(data, 2, Len(data) - 2) 'strip off {,} items = Split(data, ",") For Each item In items If item Like key & ":*" Then item = Split(item, ":")(1) item = Mid(item, 2, Len(item) - 2) 'strip off "," JsonExtractor = item Exit Function End If Next item 'raise error if not found: JsonExtractor = CVErr(xlErrValue) End Function 

然后在B2中input公式=JsonExtractor($A2,B$1)并复制:

在这里输入图像说明