4
我在本週早些時候發佈了一個關於HTML轉換爲Excel的問題,這對我來說很合適。我給出的示例宏代碼在將代碼從HTML格式轉換爲Excel單元方面做得很好(謝謝Siddharth Rout!)。我現在遇到的問題似乎無法在任何地方找到答案,這與IE對象如何處理Excel中的段落,中斷和列表項有關。 p,br和li將文本移動到源單元格下面的單元格中,覆蓋這些單元格中的所有數據。是否有任何方法可以讓HTML塊僅顯示在一個單元格中(意思是每個新行標記只會在同一個單元格中創建一個新行)?HTML to Excel格式轉換 - 在同一單元格中打破和li
VBA代碼
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
<p> Here are some possible uses:</p> <ul> <li><font color = "red"> syntax highlighting code snippets</font></li> <li style ="font-weight:bold; color: orange">validating credit card numbers, phone numbers, and zip codes</li> <li style = "font-style: italic">styling email addresses and tags</li> </ul>
樣本輸出正顯示在多行(想在一個小區中,以顯示在多行 - 類似方式轉+進入工作)
Here are some possible uses:
syntax highlighting code snippets
**validating credit card numbers, phone numbers, and zip codes**
*styling email addresses and tags*