Excel - 查找大字符串中的子字符串列表

Excel - 查找大字符串中的子字符串列表

我一直在努力解决以下问题;可能会有点挑战。

我有一个从 XML 应用程序导出的 Excel 文件。

第 1 页包含如下字符串行。每个奇数行都有大约 10 个这样的字符串,但这可能会有所不同。(我正在寻找一种解决方案来填充偶数行;见下文。)

第 2 页,A 列包含一系列字符串,如Measurement_1Ref_NoMaximum_Velocity,称为属性

我需要在每个奇数行的每个单元格中查找这些属性中的每一个第 1 页,并粘贴每个独特的属性作为这些字符串中的子字符串出现在下面的新行中,每个字符串都位于自己的单元格中。

请注意,生成的行中的每个值都需要是唯一的。

是否有一些函数、正则表达式或 VBA 脚本可以做到这一点?我在论坛和其他地方进行了广泛的搜索,但未能自己做到。

我希望这一切都有意义,但我很乐意解释任何胡言乱语的东西!


第 1 行

Cell A1:
<ref attrid="Measurement_1" equalsign="=" includeattrname="false" resolveto="valueandunit" separator=""><ref attrid="Measurement_1" equalsign="=" includeattrname="false" resolveto="valueandunit" separator=" - "></ref></ref>

Cell B1:
"<ref attrid="Ref_No" equalsign="=" includeattrname="false" resolveto="valueandunit" separator=""><ref attrid="Unit" equalsign="=" includeattrname="false" resolveto="valueandunit" separator=" "><ref attrid="Vector" equalsign="=" includeattrname="false" resolveto="value" separator=" (Dia)"><ref attrid="Object_Diameter" equalsign="=" includeattrname="false" resolveto="unit" separator=""><ref attrid="Thread_Size" equalsign="=" includeattrname="false" resolveto="valueandunit" separator=","><ref attrid="Object_Length" equalsign="=" includeattrname="false" resolveto="value" separator=" "><ref attrid="Object_Length" equalsign="=" includeattrname="false" resolveto="value" separator=" of ">"

Cell C1:
CONCATENATE("This ", LOWER(VAL("Device_Type")),F(AND(EXACT(VAL("Max_Temperature_Range"),("")),EXACT(VAL("Min_Temperature_Range"),"")),".",CONCATENATE("appeared to operate safely from a minimum temperature of ", VAL("Min_Temperature_Range"),UNIT("Min_Temperature_Range")," to a maximum temperature of ", VAL("Max_Temperature_Range"),UNIT("Max_Temperature_Range"),".")))

期望输出第 2 行看起来是这样的:

Cell A2:Measurement_1
Cell B2:Ref_No
Cell C2:Object_Diameter
Cell D2:Object_Length
Cell E2:Device_Type
Cell F2:Max_Temperature_Range
Cell G2:Min_Temperature_Range

答案1

您的 XML 字符串看起来很奇怪 - 有很多不完整的标签?

无论如何,我会从 XML 文件开始,然后使用 Power Query 插件加载它。它有一个特定的“来自 XML”处理程序,您可以使用 Power Query 命令轻松地沿途调整数据。

这是我使用 XML 内容的编辑版本构建的示例(我添加了根元素和结束标记以使其成为有效的 XML 文件)。

Power Query - 来自 XML 文件示例

要实现您想要的效果,唯一需要做的就是选择属性:attrid 列并选择删除列/删除其他列。

您可以在后台看到结果 - Excel 表。每当 XML 文件发生变化时,只需点击“刷新”即可重新运行 Power Query。

相关内容