将HTML转换为VBA中的纯文本 [英] Convert html to plain text in VBA
本文介绍了将HTML转换为VBA中的纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含html单元格的Excel工作表。我如何批量将它们转换为纯文本?目前有这么多无用的标签和样式。我想从头开始编写它,但如果我可以获取纯文本,它将变得容易得多。
我可以编写一个脚本将html转换为纯文本所以如果你不能想到VBA中的解决方案,那么也许你可以消化我如何将细胞数据传递到网站并检索数据。
方法设置对Microsoft HTML对象库的引用。
函数HtmlToText(sHTML)As String
Dim oDoc As HTMLDocument
Set oDoc = New HTMLDocument
oDoc.body.innerHTML = sHTML
HtmlToText = oDoc.body.innerText
End Function
Tim
I have an Excel sheet with cells containing html. How can I batch convert them to plaintext? At the moment there are so many useless tags and styles. I want to write it from scratch but it will be far easier if I can get the plain text out.
I can write a script to convert html to plain text in PHP so if you can't think of a solution in VBA then maybe you can sugest how I might pass the cells data to a website and retrieve the data back.
解决方案
Set a reference to "Microsoft HTML object library".
Function HtmlToText(sHTML) As String
Dim oDoc As HTMLDocument
Set oDoc = New HTMLDocument
oDoc.body.innerHTML = sHTML
HtmlToText = oDoc.body.innerText
End Function
Tim
这篇关于将HTML转换为VBA中的纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文