带有标记的 HTML 文本,用于 Excel 单元格中的格式化文本 [英] HTML Text with tags to formatted text in an Excel cell
本文介绍了带有标记的 HTML 文本,用于 Excel 单元格中的格式化文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将 HTML 导入到 Excel 中,以便将其格式化为富文本(最好使用 VBA)?基本上,当我粘贴到 Excel 单元格时,我正在寻找:
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>
进入这个:
这是一个测试.这段文字是粗体还是斜体
This is a test. Will this text be bold or italic
推荐答案
是的,这是可能的 :) 事实上,让 Internet Explorer 为你做那些肮脏的工作 ;)
Yes it is possible :) In fact let Internet Explorer do the dirty work for you ;)
久经考验
我的假设
- 我假设 html 文本位于 Sheet1 的单元格 A1 中.您也可以改用变量.
- 如果您有一列充满了 html 值,那么只需将以下代码放入一个循环中
代码
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
快照
这篇关于带有标记的 HTML 文本,用于 Excel 单元格中的格式化文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文