以下のようなExcelシートにHTMLタグ付きのデータがあります。
<b>This is test data<br>Nice
<div> Go on this is next Cell
Very goood <b>.....</b>
SO、基本的には、Excelシートのすべてのhtmlタグを削除またはスペースに置き換えたいです。
以下のようなExcelシートにHTMLタグ付きのデータがあります。
<b>This is test data<br>Nice
<div> Go on this is next Cell
Very goood <b>.....</b>
SO、基本的には、Excelシートのすべてのhtmlタグを削除またはスペースに置き換えたいです。
パターンReplace All
で適用:<*>
これを開くには、リボンに移動するHome > Find & Select > Replace...
か、単にCTRL+を押しHます。
余分なスペースは、TRIM
関数を使用してさらに削除できます。幸運を!
Excel で VBA を開き (Alt + F11)、右側のプロジェクト エクスプローラーでプロジェクト名 (スプレッドシート名) をクリックします。挿入 -> 新しいモジュール。以下のユーザー定義関数をモジュール Window に貼り付けます。マクロを許可する .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 を押すことでこれを行うことができます。"find: <br>
" "replace: (Alt を押したまま NUMPAD でタイプ 0010 を使用します。replace で小さなドットが点滅するはずです)。ウィンドウ、次に「すべて置換」を押します)。
以下のコードをユーザー モジュールに貼り付けます (alt + f11、シート 1 を右クリック -> 挿入 -> モジュール -> コードの貼り付け)
[ファイル] -> [オプション] -> [リボンのカスタマイズ] -> [開発者] チェックボックスをオンにして、ボタンを作成します。次に、開発者タブ -> 挿入 -> ボタン -> に移動し、ボタンを配置して右クリック -> マクロの割り当て -> タグの削除を選択します。
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