简体   繁体   English

在Excel中,如何将HTML文本转换为多个单元格中的常规文本

[英]In Excel, how to convert HTML text to regular text in multiple cells

I have a excel workbook with multiple sheets, each having multiple cells containing HTML text. 我有一个包含多个工作表的Excel工作簿,每个工作簿都有多个包含HTML文本的单元格。 How can I convert this text directly to regular text with all the formatting defined in HTML tags. 如何将此文本直接转换为HTML标记中定义的所有格式的常规文本。 Is it possible to have a macro which can scan all such cells and convert them at once? 是否有可能有一个宏可以扫描所有这些细胞并立即转换它们?

try the below function to strip all the html tags (except Bold and break) and to get regular text by parsing the html text to this function like striphtml(your html text). 尝试使用下面的函数去除所有的html标签(Bold和break除外),并通过将html文本解析为此函数来获取常规文本,如striphtml(你的html文本)。

Function StripHTML(sInput As String) As String
    Dim RegEx As Object
    Set RegEx = CreateObject("vbscript.regexp")
    Dim sOut As String
    With RegEx
        .Global = True
        .IgnoreCase = True
        .MultiLine = True
        .Pattern = "<(?!/?(?:br|b)\b)[^>]*>" 'Regular Expression for HTML Tags.
    End With
    sOut = RegEx.Replace(sInput, "")
    StripHTML = sOut
    Set RegEx = Nothing
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM