简体   繁体   English

如何将Excel中的常规文本替换为HTML无序列表(用于导出为CSV)?

[英]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? 如何将Excel工作表中的特定列转换为HTML无序列表? 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: 假设数据在另一列中的ColumnA中:

="<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. 复制到适合的位置,在顶部添加<ul> ,在底部添加<ul> </ul> ,选择另一列“复制”,“选择性粘贴”,“顶部的值”,然后删除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. 例如: =getUnorderedList(A1:A10) -您将无法使用A:A类型引用来将整列用作其当前编写的内容。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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