excel公式去掉html
我想从文本值的左边和右边去掉所有的html:
我有这个…
<option value="41">GECommonUI</option>
我想得到这个…
GECommonUI
设置对MS Forms 2.0的引用以使用DataObject对象。
Public Function StripHTML(sInput As String) As String Dim rTemp As Range Dim oData As DataObject Set oData = New DataObject oData.SetText "<html><style>br{mso-data-placement:same-cell;}</style>" & sInput & "</html>" oData.PutInClipboard Set rTemp = Workbooks.Add.Worksheets(1).Range("a1") rTemp.Parent.PasteSpecial "Unicode Text" StripHTML = rTemp.Text rTemp.Parent.Parent.Close False Set rTemp = Nothing Set oData = Nothing End Function
有关更多信息,请参阅http://www.dailydoseofexcel.com/archives/2005/02/23/html-in-cells-ii/ 。
您可以在下面的页面上下载一个带有工作用户定义的函数= stripHTML()的Excel文件。 该文件有一个工作示例和说明。 这将解决您的问题。 请注意,您将不得不允许此Excel文档中的macros使该function正常工作。
http://jfrancisconsulting.com/how-to-strip-html-tags-in-excel/
我的function如何不同?
我发现的大多数函数都做了全局查找和replace,以删除括号内的所有HTML标记。
但是,这会删除某些换行符,导致最终的结果看起来像是一团糟的文本。 我修改了一个现有的函数来添加行空格,以便最终结果保持适当的换行符。
其次,全局HTML只replace括号中的属性<>所有的HTML特殊符号将保留。 防爆。 而不是&符号,您将剩下HTML版本&。 为了解决这个问题,我插入了87个replace行来replace所有的HTML符号和字符。
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
在Excel中select所有
打开replace(ctrl + f)
replace<*>
什么都没有
或者使用perl正则expression式
$ line =“这是一些HTML和文字的文字”;
$ line =〜s /<(.*?)>// gi;
您可以尝试VBScripts正则expression式支持 。
家伙这是一个简单的string函数集。 因为我不能在Excelstring函数的速度,这是一个痛苦,我要弄清楚…
在编程语言中,这将像mid(start,length)一样得到来自完整的htmlstring的值 – 诀窍是获得长度作为开始位置减去结束html长度的长度)
mid(pos(“>”)+ 2,len(string)-pos(“>”))