简体   繁体   中英

Excel Autofilter in VB.NET

In my application I'm exporting an Excel file by getting the layout of a HTML page. So, in my codebehind, I'm modifying the HTML layout and inserting itens on it like if it was a webpage. Doing it that way, I don't need to use any external library and, as the data I'm exporting is just a table, I don't need nothing complex to handle it. My question is: there is a way to create an AutoFilter by just modifying the HTML tags? I mean, like if a put a < b>Column Name in the HTML, when exporting to Excel it will become , it is possible to do the same thing with the AutoFilter? ,是否可以使用AutoFilter做同样的事情?

A macro like this may help you. Sorry for the formatting.

Sub HTMLConvert()

Dim X As Integer
Dim Y As Integer

'Make your range of rows here
For X = 1 To 50

'Make your range of columns here
For Y = 1 To 10

'Each tag that you want to look for needs one of these if statements
If InStr(1, Cells(X, 1), "<b>") > 0 Then

'Keep in mind this solution will only bold the whole cell, not part of one.

Cells(X, 1).Font.Bold = True
Cells(X, 1) = Replace(Cells(X, 1), "<b>", "")

'If you have a closing tag, like </b>, make sure you clear it too

End If

Next

Next

End Sub

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