VB.NET中的Excel自动过滤器

时间:2009-11-13 19:01:46

标签: html vb.net excel autofilter

在我的应用程序中,我通过获取HTML页面的布局导出Excel文件。因此,在我的代码隐藏中,我正在修改HTML布局并在其上插入itens,就像它是一个网页一样。这样做,我不需要使用任何外部库,因为我导出的数据只是一个表,我不需要任何复杂的处理它。我的问题是:有一种方法可以通过修改HTML标签来创建AutoFilter吗?我的意思是,就像放一个< b> HTML中的列名,当导出到Excel时,它将变为粗体,可以使用自动过滤器执行相同的操作吗?

1 个答案:

答案 0 :(得分:0)

像这样的宏可能会对你有所帮助。抱歉格式化。

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