HTML文本与Excel单元格中的格式化文本的标签 [英] HTML Text with tags to formatted text in an Excel cell
本文介绍了HTML文本与Excel单元格中的格式化文本的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< html>< p>这是一个测试。此文本是否为< b> bold< / b>或者< i> italic< / i>< / p>< / html>
到这个:
这是一个测试。这个文字是 bold 还是 italic
解决方案
实际上让Internet Explorer为你做肮脏的工作;)
TRIED AND TESTED
我的假设
- 我假设html文本在Sheet1的单元格A1中。您也可以使用一个变量。
- 如果您的列中已经包含html值,那么只需将下面的代码放在循环中
代码
Sub Sample()
Dim Ie As Object
设置Ie = CreateObject(InternetExplorer.Application)
带有Ie
.Visible = False
。导航about:blank
.document.body.InnerHTML = Sheets(Sheet1)。Range(A1)。Value
.document.body。 createtextrange.execCommandCopy
ActiveSheet.Paste目的地:= Sheets(Sheet1)。范围(A1)
.Quit
结束
结束Sub
SNAPSHOT
HTH
Sid
Is there a way to take HTML and import it to excel so that it is formatted as rich text (preferably by using VBA)? Basically, when I paste to an Excel cell, I'm looking to turn this:
<html><p>This is a test. Will this text be <b>bold</b> or <i>italic</i></p></html>
into this:
This is a test. Will this text be bold or italic
解决方案
Yes it is possible :) In fact let Internet Explorer do the dirty work for you ;)
TRIED AND TESTED
MY ASSUMPTIONS
- I am assuming that the html text is in Cell A1 of Sheet1. You can also use a variable instead.
- If you have a column full of html values, then simply put the below code in a loop
CODE
Sub Sample()
Dim Ie As Object
Set Ie = CreateObject("InternetExplorer.Application")
With Ie
.Visible = False
.Navigate "about:blank"
.document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value
.document.body.createtextrange.execCommand "Copy"
ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")
.Quit
End With
End Sub
SNAPSHOT
HTH
Sid
这篇关于HTML文本与Excel单元格中的格式化文本的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文