开发者

Excel Autofilter in VB.NET

开发者 https://www.devze.com 2022-12-11 04:21 出处:网络
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 t

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 Bold, it is possib开发者_运维问答le to do the same thing with the 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
0

精彩评论

暂无评论...
验证码 换一张
取 消