Hướng dẫn can you write html in excel? - bạn có thể viết html trong excel không?

Tốt đẹp! Rất lắt léo.

Tôi đã thất vọng vì Excel không cho phép chúng tôi dán vào một ô được hợp nhất và cũng dán kết quả có chứa sự phá vỡ thành các hàng liên tiếp bên dưới ô "mục tiêu", vì điều đó có nghĩa là nó đơn giản là không hiệu quả với tôi. Tôi đã thử một vài điều chỉnh (unmerge/remerge, v.v.) nhưng sau đó Excel đã bỏ bất cứ thứ gì dưới một giờ nghỉ, vì vậy đó là một ngõ cụt.

Cuối cùng, tôi đã đưa ra một thói quen sẽ xử lý các thẻ đơn giản và không sử dụng bộ chuyển đổi Unicode "gốc" đang gây ra sự cố với các trường được hợp nhất. Hy vọng những người khác thấy điều này hữu ích:

Public Sub AddHTMLFormattedText(rngA As Range, strHTML As String, Optional blnShowBadHTMLWarning As Boolean = False)
    ' Adds converts text formatted with basic HTML tags to formatted text in an Excel cell
    ' NOTE: Font Sizes not handled perfectly per HTML standard, but I find this method more useful!

    Dim strActualText As String, intSrcPos As Integer, intDestPos As Integer, intDestSrcEquiv() As Integer
    Dim varyTags As Variant, varTag As Variant, varEndTag As Variant, blnTagMatch As Boolean
    Dim intCtr As Integer
    Dim intStartPos As Integer, intEndPos As Integer, intActualStartPos As Integer, intActualEndPos As Integer
    Dim intFontSizeStartPos As Integer, intFontSizeEndPos As Integer, intFontSize As Integer

    varyTags = Array("", "", "", "", "", "", "", "", "", "")

    ' Remove unhandled/unneeded tags, convert 
and

tags to line feeds strHTML = Trim(strHTML) strHTML = Replace(strHTML, "", "") strHTML = Replace(strHTML, "", "") strHTML = Replace(strHTML, "

", "") While LCase(Right$(strHTML, 4)) = "

" Or LCase(Right$(strHTML, 4)) = "
" strHTML = Left$(strHTML, Len(strHTML) - 4) strHTML = Trim(strHTML) Wend strHTML = Replace(strHTML, "
", vbLf) strHTML = Replace(strHTML, "

", vbLf) strHTML = Trim(strHTML) ReDim intDestSrcEquiv(1 To Len(strHTML)) strActualText = "" intSrcPos = 1 intDestPos = 1 Do While intSrcPos <= Len(strHTML) blnTagMatch = False For Each varTag In varyTags If LCase(Mid$(strHTML, intSrcPos, Len(varTag))) = varTag Then blnTagMatch = True intSrcPos = intSrcPos + Len(varTag) If intSrcPos > Len(strHTML) Then Exit Do Exit For End If Next If blnTagMatch = False Then varTag = "") intSrcPos = intEndPos + 1 If intSrcPos > Len(strHTML) Then Exit Do Else varTag = "" If LCase(Mid$(strHTML, intSrcPos, Len(varTag))) = varTag Then blnTagMatch = True intSrcPos = intSrcPos + Len(varTag) If intSrcPos > Len(strHTML) Then Exit Do End If End If End If If blnTagMatch = False Then strActualText = strActualText & Mid$(strHTML, intSrcPos, 1) intDestSrcEquiv(intSrcPos) = intDestPos intDestPos = intDestPos + 1 intSrcPos = intSrcPos + 1 End If Loop ' Clear any bold/underline/italic/superscript/subscript formatting from cell rngA.Font.Bold = False rngA.Font.Underline = False rngA.Font.Italic = False rngA.Font.Subscript = False rngA.Font.Superscript = False rngA.Value = strActualText ' Now start applying Formats!" ' Start with Font Size first intSrcPos = 1 intDestPos = 1 Do While intSrcPos <= Len(strHTML) varTag = " 0 Then Debug.Print Mid$(strHTML, intFontSizeStartPos, intFontSizeEndPos - intFontSizeStartPos + 1) If Mid$(strHTML, intFontSizeStartPos, 1) = "+" Then intFontSizeStartPos = intFontSizeStartPos + 1 intFontSize = 11 + 2 * Mid$(strHTML, intFontSizeStartPos, intFontSizeEndPos - intFontSizeStartPos + 1) ElseIf Mid$(strHTML, intFontSizeStartPos, 1) = "-" Then intFontSizeStartPos = intFontSizeStartPos + 1 intFontSize = 11 - 2 * Mid$(strHTML, intFontSizeStartPos, intFontSizeEndPos - intFontSizeStartPos + 1) Else intFontSize = Mid$(strHTML, intFontSizeStartPos, intFontSizeEndPos - intFontSizeStartPos + 1) End If Else ' Error! GoTo HTML_Err End If intEndPos = InStr(intSrcPos, strHTML, ">") intSrcPos = intEndPos + 1 intStartPos = intSrcPos If intSrcPos > Len(strHTML) Then Exit Do While intDestSrcEquiv(intStartPos) = 0 And intStartPos < Len(strHTML) intStartPos = intStartPos + 1 Wend If intStartPos >= Len(strHTML) Then GoTo HTML_Err ' HTML is bad! varEndTag = "" intEndPos = InStr(intSrcPos, LCase(strHTML), varEndTag) If intEndPos = 0 Then GoTo HTML_Err ' HTML is bad! While intDestSrcEquiv(intEndPos) = 0 And intEndPos > intSrcPos intEndPos = intEndPos - 1 Wend If intEndPos > intSrcPos Then intActualStartPos = intDestSrcEquiv(intStartPos) intActualEndPos = intDestSrcEquiv(intEndPos) rngA.Characters(intActualStartPos, intActualEndPos - intActualStartPos + 1) _ .Font.Size = intFontSize End If End If intSrcPos = intSrcPos + 1 Loop 'Now do remaining tags intSrcPos = 1 intDestPos = 1 Do While intSrcPos <= Len(strHTML) If intDestSrcEquiv(intSrcPos) = 0 Then ' This must be a Tag! For intCtr = 0 To UBound(varyTags) Step 2 varTag = varyTags(intCtr) intStartPos = intSrcPos + Len(varTag) While intDestSrcEquiv(intStartPos) = 0 And intStartPos < Len(strHTML) intStartPos = intStartPos + 1 Wend If intStartPos >= Len(strHTML) Then GoTo HTML_Err ' HTML is bad! If LCase(Mid$(strHTML, intSrcPos, Len(varTag))) = varTag Then varEndTag = varyTags(intCtr + 1) intEndPos = InStr(intSrcPos, LCase(strHTML), varEndTag) If intEndPos = 0 Then GoTo HTML_Err ' HTML is bad! While intDestSrcEquiv(intEndPos) = 0 And intEndPos > intSrcPos intEndPos = intEndPos - 1 Wend If intEndPos > intSrcPos Then intActualStartPos = intDestSrcEquiv(intStartPos) intActualEndPos = intDestSrcEquiv(intEndPos) With rngA.Characters(intActualStartPos, intActualEndPos - intActualStartPos + 1).Font If varTag = "" Then .Bold = True ElseIf varTag = "" Then .Italic = True ElseIf varTag = "" Then .Underline = True ElseIf varTag = "" Then .Superscript = True ElseIf varTag = "" Then .Subscript = True End If End With End If intSrcPos = intSrcPos + Len(varTag) - 1 Exit For End If Next End If intSrcPos = intSrcPos + 1 intDestPos = intDestPos + 1 Loop Exit_Sub: Exit Sub HTML_Err: ' There was an error with the Tags. Show warning if requested. If blnShowBadHTMLWarning Then MsgBox "There was an error with the Tags in the HTML file. Could not apply formatting." End If End Sub

Lưu ý Điều này không quan tâm đến việc làm tổ thẻ, thay vào đó chỉ yêu cầu một thẻ gần cho mọi thẻ mở và giả sử thẻ đóng gần thẻ mở áp dụng cho thẻ mở. Các thẻ lồng nhau đúng sẽ hoạt động tốt, trong khi các thẻ lồng nhau không đúng sẽ không bị từ chối và có thể hoặc không hoạt động.

Bạn có thể đặt HTML vào excel không?

Trên menu tệp, nhấp vào Nhập.Trong hộp thoại Nhập, nhấp vào tùy chọn cho loại tệp bạn muốn nhập, sau đó nhấp vào Nhập.Trong hộp thoại Chọn tệp, định vị và nhấp vào tệp CSV, HTML hoặc văn bản mà bạn muốn sử dụng làm phạm vi dữ liệu bên ngoài, sau đó nhấp vào Nhận dữ liệu.

HTML có thể được mở trong Excel không?

Trong Excel, chọn "Tệp" và sau đó "Mở ...".Điều hướng đến thư mục/thư mục nơi bạn đã lưu dữ liệu.Thay đổi "Tệp loại:" thành "Tài liệu HTML".Chọn tệp bạn đã lưu và nhấp vào "Mở".