我在 excel 表中有一个带有 HTML 标签的数据,如下所示:
<b>This is test data<br>Nice
<div> Go on this is next Cell
Very goood <b>.....</b>
所以,基本上我想在excel表中删除或替换所有带有空格的html标签。
我在 excel 表中有一个带有 HTML 标签的数据,如下所示:
<b>This is test data<br>Nice
<div> Go on this is next Cell
Very goood <b>.....</b>
所以,基本上我想在excel表中删除或替换所有带有空格的html标签。
应用Replace All
模式<*>
:
要打开它,请转到功能区Home > Find & Select > Replace...
或只需按CTRL+ H。
可以使用TRIM
函数进一步删除多余的空格。祝你好运!
在 Excel 中打开 VBA(Alt +F11),在右侧的项目资源管理器中单击项目名称(电子表格名称)。插入 -> 新模块。将下面的用户定义函数粘贴到模块窗口中。另存为允许宏的 .XLSM。
假设您的数据位于单元格 A2 中,请键入函数“=StripHTML(A2)”。您还可以在此处下载一个工作示例:
http://jfrancisconsulting.com/how-to-strip-html-tags-in-excel/
Function StripHTML(cell As Range) As String
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.regexp")
Dim sInput As String
Dim sOut As String
sInput = cell.Text
sInput = Replace(sInput, "\x0D\x0A", Chr(10))
sInput = Replace(sInput, "\x00", Chr(10))
'replace HTML breaks and end of paragraphs with line breaks
sInput = Replace(sInput, "</P>", Chr(10) & Chr(10))
sInput = Replace(sInput, "<BR>", Chr(10))
'replace bullets with dashes
sInput = Replace(sInput, "<li>", "-")
'add back all of the special characters
sInput = Replace(sInput, "–", "–")
sInput = Replace(sInput, "—", "—")
sInput = Replace(sInput, "¡", "¡")
sInput = Replace(sInput, "¿", "¿")
sInput = Replace(sInput, """, "")
sInput = Replace(sInput, "“", "")
sInput = Replace(sInput, "”", "")
sInput = Replace(sInput, "", "'")
sInput = Replace(sInput, "‘", "'")
sInput = Replace(sInput, "’", "’")
sInput = Replace(sInput, "«", "«")
sInput = Replace(sInput, "»", "»")
sInput = Replace(sInput, " ", " ")
sInput = Replace(sInput, "&", "&")
sInput = Replace(sInput, "¢", "¢")
sInput = Replace(sInput, "©", "©")
sInput = Replace(sInput, "÷", "÷")
sInput = Replace(sInput, ">", ">")
sInput = Replace(sInput, "<", "<")
sInput = Replace(sInput, "µ", "µ")
sInput = Replace(sInput, "·", "·")
sInput = Replace(sInput, "¶", "¶")
sInput = Replace(sInput, "±", "±")
sInput = Replace(sInput, "€", "€")
sInput = Replace(sInput, "£", "£")
sInput = Replace(sInput, "®", "®")
sInput = Replace(sInput, "§", "§")
sInput = Replace(sInput, "™", "™")
sInput = Replace(sInput, "¥", "¥")
sInput = Replace(sInput, "á", "á")
sInput = Replace(sInput, "Á", "Á")
sInput = Replace(sInput, "à", "à")
sInput = Replace(sInput, "À", "À")
sInput = Replace(sInput, "â", "â")
sInput = Replace(sInput, "Â", "Â")
sInput = Replace(sInput, "å", "å")
sInput = Replace(sInput, "Å", "Å")
sInput = Replace(sInput, "ã", "ã")
sInput = Replace(sInput, "Ã", "Ã")
sInput = Replace(sInput, "ä", "ä")
sInput = Replace(sInput, "Ä", "Ä")
sInput = Replace(sInput, "æ", "æ")
sInput = Replace(sInput, "Æ", "Æ")
sInput = Replace(sInput, "ç", "ç")
sInput = Replace(sInput, "Ç", "Ç")
sInput = Replace(sInput, "é", "é")
sInput = Replace(sInput, "É", "É")
sInput = Replace(sInput, "è", "è")
sInput = Replace(sInput, "È", "È")
sInput = Replace(sInput, "ê", "ê")
sInput = Replace(sInput, "Ê", "Ê")
sInput = Replace(sInput, "ë", "ë")
sInput = Replace(sInput, "Ë", "Ë")
sInput = Replace(sInput, "í", "í")
sInput = Replace(sInput, "Í", "Í")
sInput = Replace(sInput, "ì", "ì")
sInput = Replace(sInput, "Ì", "Ì")
sInput = Replace(sInput, "î", "î")
sInput = Replace(sInput, "Î", "Î")
sInput = Replace(sInput, "ï", "ï")
sInput = Replace(sInput, "Ï", "Ï")
sInput = Replace(sInput, "ñ", "ñ")
sInput = Replace(sInput, "Ñ", "Ñ")
sInput = Replace(sInput, "ó", "ó")
sInput = Replace(sInput, "Ó", "Ó")
sInput = Replace(sInput, "ò", "ò")
sInput = Replace(sInput, "Ò", "Ò")
sInput = Replace(sInput, "ô", "ô")
sInput = Replace(sInput, "Ô", "Ô")
sInput = Replace(sInput, "ø", "ø")
sInput = Replace(sInput, "Ø", "Ø")
sInput = Replace(sInput, "õ", "õ")
sInput = Replace(sInput, "Õ", "Õ")
sInput = Replace(sInput, "ö", "ö")
sInput = Replace(sInput, "Ö", "Ö")
sInput = Replace(sInput, "ß", "ß")
sInput = Replace(sInput, "ú", "ú")
sInput = Replace(sInput, "Ú", "Ú")
sInput = Replace(sInput, "ù", "ù")
sInput = Replace(sInput, "Ù", "Ù")
sInput = Replace(sInput, "û", "û")
sInput = Replace(sInput, "Û", "Û")
sInput = Replace(sInput, "ü", "ü")
sInput = Replace(sInput, "Ü", "Ü")
sInput = Replace(sInput, "ÿ", "ÿ")
sInput = Replace(sInput, "", "´")
sInput = Replace(sInput, "", "`")
'replace all the remaining HTML Tags
With RegEx
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "<[^>]+>" 'Regular Expression for HTML Tags.
End With
sOut = RegEx.Replace(sInput, "")
StripHTML = sOut
Set RegEx = Nothing
End Function
由于上面的宏对我不起作用,我自己修复了它。这是我的第一个脚本,如果你们可以改进它,让它更快,添加更多,那么你就更受欢迎了!
好的,伙计们,我以前没有编程经验(除了 6 年前的一些非常基本的 Java),但在一些帮助下,很多猜测(实际上是几个小时)我设法制作了这个脚本,它就像一个魅力来删除大部分和8#text 但它不替换<BR>
为换行符(您可以通过按 CTRL + H 来执行此操作,“查找:<br>
”“替换:(现在按住 ALT 并在数字键盘上使用类型 0010。替换中的小点应该闪烁窗口,然后点击“全部替换”)。
将下面的代码粘贴到用户模块中(alt +f11,右键Sheet1->insert->Module->paste code)
并通过文件->选项->自定义功能区->选中开发人员复选框来制作一个按钮。然后转到开发人员选项卡->插入->按钮->然后放置按钮并右键单击->分配宏->选择RemoveTags。
Sub RemoveTags()
Dim r As Range
Selection.NumberFormat = "@" 'set cells to text numberformat
With CreateObject("vbscript.regexp")
.Pattern = "\<.*?\>"
.Global = True
For Each r In Selection
r.Value = Replace(.Replace(r.Value, ""), "’", " ")
r.Value2 = Replace(.Replace(r.Value2, ""), "–", " ")
Next r
For Each r In Selection
r.Value = Replace(.Replace(r.Value, ""), "‘", " ")
r.Value2 = Replace(.Replace(r.Value2, ""), "
", " ")
Next r
For Each r In Selection
r.Value = Replace(.Replace(r.Value, ""), "
", " ")
r.Value2 = Replace(.Replace(r.Value2, ""), "’s", " ")
Next r
End With
End Sub
Private Sub CommandButton1_Click()
End Sub