简体   繁体   中英

How to replace regular text in Excel into HTML unordered list (for export to CSV)?

How can I convert a specific column in an Excel sheet to HTML unordered list? Make it go from this:

Item 1
Item 2
Item 3

to:

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>

I've searched the web and can't find anything even remotely close to the solution.

Assuming data is in ColumnA, in another column:

="<li>"&A1&"</li>"

copied down to suit, add <ul> at the top, </ul> at the bottom, select the another column Copy, Paste Special, Values over the top and delete ColumnA.

This might not work, wrote it in notepad.. If you add this to a new module, you can use it like a formula, specifying the range you want to convert to a list.

eg: =getUnorderedList(A1:A10) - you wont be able to use A:A type references to use the entire column as its currently written.

Public Function getUnorderedList(ByRef Target As Range) As String
Dim Result As String: Result = ""
Dim Cell As Variant

    For Each Cell in Target.Cells
        Result = Result & "<li>" & Cell.Value & "</li>" & vbNewLine 
    Next Cell

    getUnorderedList = "<ul>" & vbNewLine & Result & "</ul>"
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM